OK. I have a Spring MVC controller method as below:
public String getInformationByGID(@ModelAttribute("geoInfoParam") @Valid GeoInfoParam geoInfoParam, Model model ,BindingResult result)
GeoInfoParam class defines has a number of inputs with @NotNull, @Size annotated validations, which I expect to be executed when I submit form (as I have @Valid with ModelAttribute). But what happened, When I click submit, page showed me 400 error and did not show anyother information in log.
I debugged the execution flow and found that org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.java ( which is part HandlerAdapter execution).handleBindException is called when there is no BindingResult followed by ModelAttribute and this method sets response with 400 code. The lesson I learned is If you have a form(ModelAttribute) annotated with @Valid, make sure it is followed by BindingResult immediately. So I have changed my controller method signature as below:
public String getInformationByGID(@ModelAttribute("geoInfoParam") @Valid GeoInfoParam geoInfoParam, BindingResult result, Model model)
Silly Me. Now everthing is fine. Hope this helps someone.
NB: I use Spring MVC 3.2.8 and Hibernate validator 4.2.0 final
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With