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 ........
}
thanks!!
Big thanks! Your post saved my day))
Thanks man.
thanks you really saved me
Explained big problem in a simple manner.
many many thank you very much, all day looking for this!!!!!!!!!!!!!!!!!!!!!!!!
Many thanks,