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!
FooBarController.java
-
-
@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,
-
{
-
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,
-
{
-
// the rest of code ……..
-
}
-

Posted in 



thanks!!
Big thanks! Your post saved my day))
Thanks man.
thanks you really saved me