File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i map different Actionform class to single Action class

 
Mohit Mehta
Greenhorn
Posts: 25
  • 0
  • 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.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • 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.
 
Trevor Whitehead
Greenhorn
Posts: 16
  • 0
  • 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.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic