Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Struts, submit button with parameters

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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,
Sim085
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

regards,
Sim085
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic