How do I bypass Spring validation of "int" field when user cancels?
I have added no overt binding or validation meta-data to my application. I am relying on jQuery client-side validation.
However, two of my domain classes have int properties. When the user cancels out of a form and leaves that property's field blank or enters a non-int, I get a Spring validation error upon cancel.
I have combed the web and searched this forum. I saw a number of references to this problem vis a vis Spring 2 non-annotated controllers and WebFlow, but not Spring 3 annotated controllers.
Does anyone have any suggestions? My apologies if this has been covered, but if it has, I would appreciate a pointer!
Answer is to add BindingResult to controller method signature
It seems the answer to this question is pretty simple. I added a BindingResult argument to my controller method, which traps the binding errors. I was already handling cancel, so I needed to add no further code:
public ModelAndView saveNewAnswer (Answer answer, BindingResult bindingResult, HttpServletRequest request)
if (WebUtils.hasSubmitParameter (request, "cancel"))
return new ModelAndView ("secure/answer/manageAnswers", "resultMap", createAnswerMap (answer.getQuestion()));
// process the form and return a ModelAndView