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.

How to submit a form back to its controller?

Oct 27th, 2004, 04:40 PM

Hi all,

I'm trying to code a small form which enables the user to add/delete an object to a list, or alternately, save all of the objects on the page. Importantly, I'm trying to accomplish all of this with one form and one controller since it seems to be a simple repetitive operation in which only the number of objects displayed varies in the end...

I've successfully coded the 'save' part of the operation, but adding and deleting of the individual objects (i.e. text input boxes of a form) are causing me a major headache.

Essentially I'm having trouble with submitting the form with the "add" parameter, and having the controller call all of it's setup methods again (i.e. showForm, formBackingObject, initBinder, etc.) since they are necessary for proper dislplay of the form...

I know this is likely a noobish mistake, but I'm just starting out in Spring and am stuck at this point. Any help would be greatly appreciated... And don't be shy about suggesting other solutions.

I don't think there's anything wrong with your approach, I certainly use the same basic patterm.

Without knowing what your view needs, and what you're putting in your model, it's hard to know just where the problem lies. You need to make sure you put in your model everything your view is going to need.
For example, to make sure your model has the errors instance and the form backing object that was populated from the request, you can initialize your model with

Code:

Map map = errors.getModel&#40;&#41;;

Then add anything else to the map that your view will need.

If you've done some work on the command object, or created a new one which nees to be returned as the form backing object, you can do