aspose file tools*
The moose likes Struts and the fly likes Different pages pointing to the Same Struts Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Different pages pointing to the Same Struts Action" Watch "Different pages pointing to the Same Struts Action" New topic
Author

Different pages pointing to the Same Struts Action

AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
Hi,
I was wondering how do you go about solving the following problem:

I have a side menu. The items in the side menu does the same operation but the id is different.

For example item A with taskId = 1 when selected will go the Action and get results for taskId = 1 and display the result in a jsp page.

Item B in the side menu with taskId =2 does the same operation but results for taskId = 2.

I don't want to create separate actions for each item in the side menu. Is there any way i can pass a value to the action which can be used to get the results and then be displayed in the jsp page.

Thanks in advance

Anil
John Carnell
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 71
Hi Anil,

Are your menu items just hyperlinks? You could ways invoke the struts action directly passing the task item in the URL directly. For example, if the action you are try invoke is called process.do and your menu item has three items you could render the urls for the items:

<a href="/process.do?task=1">xxxx</a>
<a href="/process.do?task=2">xxxx</a>
<a href="/process.do?task=3">xxxx</a>

Does this help?

Thanks,
John


John Carnell<br />Principal Architect<br /> <br />Netchange, LLC<br />1161 HillCrest Heights<br />Green Bay, WI 54313<br /> <br />john.carnell@netchange.us<br /> <br /> <br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/159059228X/ref=jranch-20" target="_blank" rel="nofollow">Pro Jakarta Struts, Second Edition</a>
Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
Hi,

what you can do is to give seperate action path elements to each item in the side menu,
and all this action path will refer to the same action class. In order to differentiate between each side item use the "parameter" attribute of the action element.



"Failure is not when you fall down; its only when you fail to get up again."
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
And more in EditAdminAction.java in execute() method use


or not ??


And in JSP :

or not ??

--------------------------

Or

--------------------------

in JSP use

and in struts-config.xml



SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
In jsp you no need to mention the query string task=1


map this action1 and action2 to the same Action class, and now in action
class you have to do the following.
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
Thank you very much for the quick reply.


Anil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Different pages pointing to the Same Struts Action