Announcement Announcement Module
No announcement yet.
How do I bypass Spring validation of "int" field when user cancels? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I bypass Spring validation of "int" field when user cancels?

    Hi -

    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!


    Last edited by peahayes; Jun 16th, 2011, 02:02 PM. Reason: tried to add tags in this field! oops

  • #2
    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:

    	@RequestMapping ("/saveNewAnswer")
    	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