File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes how can i map different  Actionform class to single Action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how can i map different  Actionform class to single Action class" Watch "how can i map different  Actionform class to single Action class" New topic
Author

how can i map different Actionform class to single Action class

Mohit Mehta
Greenhorn

Joined: Jan 24, 2005
Posts: 25
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.


Regards,<br />BulletProof Monk.<br /> <br />"Nthing the Mind of man can Conceive<br />and Believe,It can achieve"
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Now, i have 2 solution to do that :

1. form per button.
2. using javascript with each action of button.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Trevor Whitehead
Greenhorn

Joined: Oct 16, 2002
Posts: 16
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

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can i map different Actionform class to single Action class
 
Similar Threads
How to know the type of request coming from the form
Struts, submit button with parameters
how to handle mutiple buttons
Diffterent action from different button
Trigger action on combo change