Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!

This is not the new thing to discover, but just a common mistake done by developer. The following stack trace is what i getting from my log file. In this example, i’ll show you the code where it actually cause the problem.

  1.  
  2. Caused by: org.springframeworksupport.HandlerMethodInvocationException:
  3. Failed to invoke handler method [public void com.foo.bar.FooBarController.doSetup
  4.  (com.foo.bar.model.FooBar, javax.portlet.ActionRequest,javax.portlet.ActionResponse,org.springframework.validation.BindingResult) nested exception is java.lang.IllegalStateException: Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!
  1. Caused by: java.lang.IllegalStateException:
  2. Errors/BindingResult argument declared without preceding model attribute.
  3. Check your handler method signature!

FooBarController.java

  1.  
  2. @Controller
  3. @RequestMapping("VIEW")
  4. public class FooBarController{
  5.        
  6.      @Autowired
  7.      private FooBarService service;
  8.  
  9.      @Autowired
  10.      @Qualifier("foobarValidator")
  11.      private FooBarValidator validator;
  12.  
  13.      @ActionMapping(params = "action=addFooBar")
  14.      public void doSetup( @ModelAttribute("foobar") FooBar foobar,
  15.            ActionRequest request,  ActionResponse response,  
  16.            BindingResult bindingResult) throws Exception
  17.      {
  18.               validator.validate(form, bindingResult);         
  19.               if (!bindingResult.hasErrors()) {                
  20.                      service.insert(foobar);
  21.                      response.setRenderParameter("action", "");
  22.               } else {
  23.                      response.setRenderParameter("action", "addFooBar");
  24.               }
  25.       } 
  26.  
  27.       @ModelAttribute("foobar")
  28.       public FooBar getCommandObject() {
  29.               return new FooBar();
  30.       }
  31. }

As you can see from the above doSetup() method call, it contains the few parameters, but the real problem is the BindingResult must be follow right after the binding object, otherwise it will complain the error. So what you need to do is adjust the position of the parameter.

  1.  
  2.   public void doSetup( @ModelAttribute("foobar") FooBar foobar,
  3.            BindingResult bindingResult, ActionRequest request,
  4.            ActionResponse response ) throws Exception
  5. {
  6.     // the rest of code ……..
  7. }
  8.  
You can leave a response, or trackback from your own site.

4 Responses to “Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!”

  1. moz says:

    thanks!!

  2. sdev says:

    Big thanks! Your post saved my day))

  3. Tino M Thomas says:

    Thanks man.

  4. mit says:

    thanks you really saved me

Leave a Reply

Security Code: