aspose file tools*
The moose likes Struts and the fly likes Action code reuse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action code reuse" Watch "Action code reuse" New topic
Author

Action code reuse

Mike Nason
Greenhorn

Joined: Apr 19, 2006
Posts: 20
We have site to browse catalog and some actions+jsp:
1. ShowItems + listItems.jsp - to show list of categories = start page
2. ShowProductList + listProducts.jsp - to show list of products
3. ShowProductDetails + productDetails.jsp - to show product details.

The thing is when user clicks on ShowProductList and list contains one item the result should be ShowProductDetails.
I have an idea to reuse ShowProductDetails and I need to do it without send redirect (because it's bad for client performance)

I have an idea to use ActionChaining but don't know how to do it, because these 2 actions have different params, and
patterns doesn't work as in type="redirect-action".
I need to be able to pass params from one action to another. Any ideas?


Wanna code??
sarada bokka
Ranch Hand

Joined: Jan 13, 2010
Posts: 80
Hi,

I am also new to struts2 .

you have mentioned 2 actions have different params

and then you said I need to be able to pass params from one action to another. Any ideas?

I guess this may help you

Struts.xml



login.jsp page

<s:form action="chain1.action" method="POST">

in the above Chain1Action parameters are carried to Chain2Action

is this you are looking for?
sarada bokka
Ranch Hand

Joined: Jan 13, 2010
Posts: 80
I forgot to mention this

You can get the Chain1Action param username in Chain2Action as below

public class Chain2Action extends ActionSupport{
private String password;
public String execute() throws Exception {
ActionContext context=ActionContext.getContext();
System.out.println("value stack value"+context.getValueStack().findString("username"));

return SUCCESS;

}
 
Don't get me started about those stupid light bulbs.
 
subject: Action code reuse
 
Similar Threads
EJB2 Query Language problems with subqueries
Chaining filter servlet
Struts2: which result type to use
Websphere unable to parse Web.xml
Can we use multiple Controllers in a single web-application?