wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts 2 - passing request parameters on the fly during redirectAction result type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - passing request parameters on the fly during redirectAction result type" Watch "Struts 2 - passing request parameters on the fly during redirectAction result type" New topic
Author

Struts 2 - passing request parameters on the fly during redirectAction result type

Mohamed Soliman
Greenhorn

Joined: Mar 09, 2010
Posts: 13
Dear all, here is my case:

I've an action which has a result type of type "redirectAction" which invokes another action (same action class but another method.For example, addUser method calla openUserPage method of UserAction class.) The problem is, I need to pass parameters between the two actions. The only way to do this is by adding the parameters on the XML, or by creating a model propery of the action class with setters and getters methods and in struts.xml. This works perfectly but my problem is, I've dozens of request parameters which I need to complete my second action. I already have the parameters in a HashMap (which is also a property of the action class) which has all the needed parameters. The only way which works for me is to add each single parameter on this hashmap into the XML file, but this sounds very annoying and not professional.

My question is, how can I add these request parameters on the fly between the two actions? I've created an interceptor and tried placing it on bottom (and top) of the defaultstack, get the the request parameters hashmap of the action from the actionInvocation object, but any added parameters to this hashmap (except the ones which already exist on it) are not recognized by the target action (and the JSPs as well).

Below is m actions code:

<package name="registerActions" extends="struts-default" namespace="/register">
<action name="addUser" method="addUser" class="com.home.client.struts.actions.UserAction">
<result name="userAdded" type="redirectAction">
<param name="namespace">/user</param>
<param name="actionName">openUserPage</param>
<!--This works fine-->
<param name="parse">true</param>
<param name="addedUserName">${userModel.userName}</param>
<param name="requestParameters">${userModel.paramsMap}</param>
</result>
<result name="error" type="dispatcher">/pages/error.jsp</result>
</action>
</package>

<package name="userActions" extends="struts-default" namespace="/user">
<action name="openUserPage" method="openUserPage" class="com.home.client.struts.actions.UserAction">
<!-- In this action and its result, I need to have access to all parameters passed in [b]paramsMap above. I need them in the URL-->[/b]
<result name="openUserPage" type="dispatcher">/pages/userPage.jsp</result>
<result name="error" type="dispatcher">/pages/error.jsp</result>
</action>
</package>


Any ideas?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts 2 - passing request parameters on the fly during redirectAction result type
 
Similar Threads
https becomes http after redirectAction
Struts2 Action Mapping Problem - No configuration found for the specified action
Post-Redirect-Get pattern with Struts 2 ModelDriven action?
Unit Testing
Junit testing for Struts2