OK so this is what I have now:
Code:
@RequestMapping(value = "/create", method = RequestMethod.POST)
public ModelAndView create(@Valid @ModelAttribute("accountForm") AccountForm accountForm, HttpServletRequest request, BindingResult bindingResult) {
...
....
}
My accountForm:
Code:
public class AccountForm {
@NotNull
@Size(min=3, max=50, message="Account name must be between 3 and 50 characters long.")
private String accountName;
@NotNull
@Size(min=3, max=50, message="Company name must be between 3 and 50 characters long.")
private String companyName;
...
}
So now when I go to the form page, and hit submit, I get an error, and the breakpoint in my create method doesn't even get run.
So the error is even before my code in the controller runs, why is
Code:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'accountForm' on field 'accountName': rejected value [null]; codes [NotNull.accountForm.accountName,NotNull.accountName,NotNull.java.lang.String,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [accountForm.accountName,accountName]; arguments []; default message [accountName]]; default message [may not be null]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
I'm confused how this could happen, even if my accountForm has validation issues, it shouldn't crash everything like this and not even go to the controller method to handle the post?