This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

SimpleFormController Errors instance first time into form.Page Title Module

SimpleFormController Errors instance first time into form.

Dec 13th, 2004, 12:54 PM

I have a jsp page that is working with the SimpleFormController. Everything works fine, but now I want to display the errors. I get the error message "add the Errors model to your ModelAndView via errors.getModel" when I try to use the tag:

The problem is I do not have a command object the first time into the jsp page because the user has not entered anything yet. I assume I do not need one version of the form to submit and one to display errors? Or am I supposed to go through a Controller just to set the BindException errors on the model? If so which Controller would I use?

Comment

Thats where my confusion lies. I do not go through my SimpleFormController the first time into the form. I thought I only went through my SimpleFormController when I hit the submit button so that I can process the data and move on.

After re-reading the workflow of the SimpleFormController I see the formBackingObject() is step 2 and step 7 says "Model gets exposed and view gets rendered, to let the user fill in the form." But how does the SimpleFormController know that I want to render the form for the first time and I am not doing a submit to process the data?

Thanks for your help! I totally appreciate it.

Comment

First time, you render the view with an empty object, or with an object with init values ( like default, or values read from the database). Then when you click submit, this object is binded with the new values, entered by the user. In the submit method, you can retrieve this object updated, and you can for exemple store it somewhere. After that, you go by default to the finishView.
You go throught the controller, each time you request his url, but you go on the submit method, only, if you post the form, with valid data.

Comment

But how does the SimpleFormController know that I want to render the form for the first time and I am not doing a submit to process the data?

It makes this decision based on the result of calling isFormSubmission() (a method of AbstractFormController). The default implementation returns false if the request is a GET, and true if it's a POST. You can override this if you want.
See the javadoc for more details.