Just wanted to chime in with a tad bit more detail...
If you have a form defined as so...
<form name="test" method="post" action="test.test"> <input type="submit" name="submit_value" value="submit_button_1"> <input type="submit" name="submit_value" value="submit_button_2"> <input type="submit" name="submit_value" value="submit_button_3"> </form>
...And in your action you do...
System.out.println(request.getParameter("submit_value"));
...You will indeed see the value of the button that was clicked.
I only wanted to mention this because I personally am not yet using the Struts <html> and <form> tags (I'm fairly new to Struts at this point), so I do not know the ins and outs of them in terms of what they are really doing behind the scenes, what HTML/scrip they might be generating, etc.
However, I think it helps to know what you can do without them, just straight HTML and Struts. I was actually not aware that an HTML form submission would do this, I had always done as a previous poster suggested in setting a hidden form field via script. But I just tried this, and it indeed does as I state.
I find this very useful because I recently wrote a small file manager application, and I'm trying to remove all script from it so that I can access it from my cell phone (which, while I have a real HTML browser rather than just the built-in WAP browser, does not support scripting of any kind)... this will allow me to remove one important piece of scripting.
And it seemed like it might be useful information in the context of this thread.
From: Riyad Kalla <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: Struts Users Mailing List <[EMAIL PROTECTED]> Subject: Re: Multiple submit buttons in the same form Date: Sat, 29 May 2004 18:42:36 -0700
Rick,
This is a great approach as well and I think we've giving good answers. 1 way you change the Form, and another way you change the Action.
I didn't know you could do it the way you described, thanks for the tip!
Rick Reumann wrote:
Riyad Kalla wrote:
1) Yes you can do it
2) Given each button a different value, like "List Products" and "List All Products"
3) Add a "buttonValue" (or some other adequetly names) property to your form for the respective action, it will capture the button clicked.
4) In your action:
if(form.getButtonValue().equals("List Products")) // do stuff else if(form.getButtonValue().equals("List All Products")) // do more stuff
You can do it much easier using either of the approachs below:
1) Use the LookUpDispatch Action. You simply give the submit button your dispatch property name (ie property="UserAction" ) then the value of the button gets looked up from a map in your LookUpDispatchAction (see the docs). Much cleaner.. although..
2) I still prefer to set a hidden variable of a dispatch Action with javascript when a button is clicked. Then simply use a regular DispatchAction or someone mentioned even a MapplingDispatchAction which I wasn't aware of (maybe this later is in Struts 1.2?). Assuming a regular dispatch action you have buttons like..
<html:submit onclick="document.yourForm.userAction.value='Update'">Update</html:submit>
<html:submit onclick="document.yourForm.userAction.value='Cancel'">Cancel</html:submit>
<html:hidden property="userAction"/>
Then just make sure you are using a DispatchAction. (In the above it's better if you use the resources properties file for you button names: <bean:message key="button.update"/> Just in case later the button names change, it's easier to modify one resources file.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE download! http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]