I have a form that is for editing a object (Like EditStudentForm) and it extends SimpleFormController. I have 2 submit buttons on the form "Save" and "Delete". How can I execute the appropriate method based on which button has been clicked?
I have a form that is for editing a object (Like EditStudentForm) and it extends SimpleFormController. I have 2 submit buttons on the form "Save" and "Delete". How can I execute the appropriate method based on which button has been clicked?
cheers,
Lili
I would just name your buttons "save" and "delete". Then in your onSubmit() method, you can add logic to detect which button was clicked:
The button's name is only sent in the request when the user clicks on it.Code:if (request.getParameter("save") != null) { // do save logic } if (request.getParameter("delete") != null) { // do delete logic }
Hope this helps,
Matt
That makes sense.
Thanks.
cheers,
Lili
i have the same problem
but i am using
<INPUT type="image" src="images/icon_last.gif" name="last" value="Last">
but this does not work
if (request.getParameter("last") != null) {
}
can't i use input type image for submitting and detect that in controllers
thanx
I believe you have to use "last.x" or "last.y" or something funky like that.
sorry mraible
can u please make that little more elaborate ..
thanx
I haven't tried it myself, but I know image-based submit buttons send "x" and "y" coordinates, rather than their name. Try this:
It's just a hunch, I could be completely wrong. ;-)Code:if (request.getParameter("last.x") != null) { }
or use a hidden field (e.g. navigate) and use a javascript method to fill this field e.g. <input type="image" onclick="document.mainForm.navigate.value='submitB yImage'">
or something similar.
thank u mraible
it worked
also rharing for ur suggestion ..
actually i am trying to avoid javascripts .. so will use mraibles method
thanx
have a look at
http://forum.springframework.org/viewtopic.php?t=1588
for a more generic form handler with multiple submits
Stuart Eccles
Technical Consultant