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.

Caused by: org.springframework...support.HandlerMethodInvocationException: 
Failed to invoke handler method [public void com.foo.bar.FooBarController.doSetup
 (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!

Caused by: java.lang.IllegalStateException: 
Errors/BindingResult argument declared without preceding model attribute. 
Check your handler method signature!

 

[googlefont font=”Enriqueta” fontsize=”30″]FooBarController.java[/googlefont]

@Controller
@RequestMapping("VIEW")
public class FooBarController{
	
     @Autowired 
     private FooBarService service;

     @Autowired
     @Qualifier("foobarValidator")
     private FooBarValidator validator;

     @ActionMapping(params = "action=addFooBar")
     public void doSetup( @ModelAttribute("foobar") FooBar foobar,
           ActionRequest request,  ActionResponse response,  
           BindingResult bindingResult) throws Exception 
     {
	      validator.validate(form, bindingResult);		
              if (!bindingResult.hasErrors()) {			
 	             service.insert(foobar);
               	     response.setRenderParameter("action", "");
              }	else {
	             response.setRenderParameter("action", "addFooBar");
              }
      }	

      @ModelAttribute("foobar")
      public FooBar getCommandObject() {
              return new FooBar();
      }
}

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.

  public void doSetup( @ModelAttribute("foobar") FooBar foobar,
           BindingResult bindingResult, ActionRequest request, 
           ActionResponse response ) throws Exception 
{
    // the rest of code ........
}
Errors/BindingResult argument declared without preceding model attribute. Check your handler method signature!

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

  • December 1, 2011 at 6:53 pm
    Permalink

    Big thanks! Your post saved my day))

    Reply
  • December 13, 2011 at 9:17 pm
    Permalink

    Thanks man.

    Reply
  • April 25, 2012 at 11:47 pm
    Permalink

    thanks you really saved me

    Reply
  • June 18, 2014 at 8:18 am
    Permalink

    Explained big problem in a simple manner.

    Reply
  • August 12, 2014 at 10:10 pm
    Permalink

    many many thank you very much, all day looking for this!!!!!!!!!!!!!!!!!!!!!!!!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.