Announcement Announcement Module
Collapse
No announcement yet.
re: display error from BindingResult Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • re: display error from BindingResult

    When you are using ModelAndView and return a BindingResult,
    if there is an error (i.e. constraint error), how do you get the error to display
    on your jsp page? In other words, how do you pass the error message
    inside result to a jsp file, to display to the user (i.e. "Error - duplicate
    name").

    For example:

    Code:
    public ModelAndView update(
    			@Valid @ModelAttribute("example") example example,
    			BindingResult result) {
    
    		if (result.hasErrors()) {
    			return new ModelAndView("example/edit").addObject(
    					"example", example);
    ...
    ...
    Thanks so much for any advice on this!

  • #2
    I usually use the <form:errors> tag. You can use it at a field level or as a group of errors.

    For field level:
    Code:
    <form:input path="foo"/>
    <form:errors path="foo"/>
    For all fields:
    Code:
    <form:errors path="*" />

    Comment

    Working...
    X