Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different pages pointing to the Same Struts Action

 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shankar Narayana
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Shankar Narayana
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the quick reply.


Anil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic