• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

how can i map different Actionform class to single Action class

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
In my project i have one jsp page with 5 buttons and each button has different functionality based on button click i want to call respective Action form and in my action class (only one) i want to check which button is clicked.
please tell me do we have any tag in struts for pagination.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, i have 2 solution to do that :

1. form per button.
2. using javascript with each action of button.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by bhumika mehta:
Hi ,
In my project i have one jsp page with 5 buttons and each button has different functionality based on button click i want to call respective Action form and in my action class (only one) i want to check which button is clicked.
please tell me do we have any tag in struts for pagination.



hi bhumika ,
In most cases there are several benefits to a single ActionForm (manageability, relationship preservation, etc...). It sounds like you just want to perform a defined operation in your Action class based on which button is selected, if this is the case check out the DispatchAction or DispatchLookup Action if you don't want to use JavaScript buttons. Let me know if you need more info.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do what you require easily.
Buttons get submitted with the rest of the form's data.

For example clicking one of these buttons:
<html:submit property="button" value="Save"/>
<html:submit property="button" value="Edit"/>
will submit a "button" parameter with the request.

I like to put accessor methods getButton/setButton in my ActionForm and then run a comparison in the Action like:
if("Save".equals(myForm.getButton())){
...
}else if("Edit".equals(myForm.getButton()){
...

If you use this method, set up constants for the "Save" and "Edit" values:
<html:submit property="button" value="<%= MyConstants.SAVE %>"/>
<html:submit property="button" value="<%= MyConstants.EDIT %>"/>
if(MyConstants.SAVE.equals(myForm.getButton())){
...
}else if(MyConstants.EDIT.equals(myForm.getButton()){
...

Don't blindly jump into this as your solution. At least check out DispatchAction as a possible solution. I don't recommend placing multiple forms on your page or using javascript to solve it.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic