Aug 27th, 2010, 03:05 AM
More commands in a form? (SimpleFormController)
I'm using Spring 2.5.5.
My question is how is it possible to have more forms or one form with more submit buttons on a jsp page?
Is SimpleFormController able to handle such a scenario? How can I specify more command objects and send the proper command based on which button was pressed?
Or maybe i misunderstood the command term here and it shouldn't mapped to actions on a page oneToOne?
Thanks in advance!
Aug 27th, 2010, 03:24 AM
If you've got more than one form on a page only one of them will be sent to the server. This would be the one a submit button was pressed in. If the command object has attributes for all the fields of all the forms, such a page can be handled by one controller. Whether that makes sense depends on the use case.
One form with multiple submit buttons is an entirely different beast:
All of the fields will be sent to the server. The simplest way to find out which button was pressed, is arguably WebUtils.hasSubmitParameter().
Aug 27th, 2010, 07:47 AM
Thank you for your answer. It does make sense this way - even though it is a little bit weird for me that you have to have all the fields of different forms in one object to be able to handle them in the controller.. is it really the pattern spring developers suggest us?
An other question meanwhile still with regard the SimpleFormController:
is it possible to have both the onSubmit and handleRequest methods overrided and still have the desired functionality?
for me it seems that in case i override the handleRequest method, the onSubmit is never called, all the requests are handled by the handleRequest method...
how should i fill in the model for the view when it is first loaded then? (in case i have just the onSubmit method but i would like to have a model there even before the form is submitted)
Aug 27th, 2010, 08:14 AM
You can have different command objects with a single controller, but then you have to assign a different URL to every form and configure the controller for every URL.
The JavaDoc for SimpleFormController (and its super classes) should answer the other questions.