File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts, submit button with parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts, submit button with parameters" Watch "Struts, submit button with parameters" New topic

Struts, submit button with parameters

Simon Joseph Aquilina
Ranch Hand

Joined: Feb 14, 2006
Posts: 102

Basically I have a form, where I want to have two buttons. One button is to save and return to another screen, while the other button is there to save and stay in the same screen.

This means that my action class needs to return a different forward depending on which button is being clicked.

Now this page is also using an ActionForm. This means that I need to submit my form inorder for the action form to be populated.

My question is; Is there a way how a submit button can also be sending a parameter when clicked?

These parameter would then be retrieved by the action class so that this would know how to forward the request.

I do not know if this is possible, if there are better ways how to do this please let me know, I am more then happy to change the design to make it good.

Also I am using the struts-html tag libs.

Thanks and Regards,
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Better ways? I am not sure but I can tell you how I have implemented this. I have a property named "specialAction" in my form and I also add that to my jsp as a hidden field. Rather than using an html:submit tag I use an html:button tag. In the onClick handler that button calls a javascript function that sets the value of specialAction and then submits the form.

You can then perform special processing in the save action if needed. I will generally append the value of the specialAction to the forward name. So for example, the standard forward might be "success" which forwards to a different page. When the page is submitted with a specialAction value of "return" then it will use the "success-return" which would redisplay the page that the user just saved.

Does that make sense?

- Brent
Simon Joseph Aquilina
Ranch Hand

Joined: Feb 14, 2006
Posts: 102
Thanks for the reply

Yes what you say makes a lot of sense. At the moment, I tried not using any javascript in my applications, however I think that this will require a modification in that!

Thanks again

I agree. Here's the link:
subject: Struts, submit button with parameters
It's not a secret anymore!