Results 1 to 2 of 2

Thread: re: display error from BindingResult

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Posts
    8

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default

    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="*" />

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •