• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Mohamed Soliman
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 name="error" type="dispatcher">/pages/error.jsp</result>

<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>

Any ideas?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!