2

I am having a weird problem when redirecting to an action from another action. In short the named variable captured in the first action (from which I am redirecting) is still preserved somehow in the value stack and it is overwriting the same named variable in the second action. I will explain via some code.

<action name="r/{seoURL}" class="ReportsAction"
    method="displayReport">
    ...
    <result name="REDIRECT_TO_NEXT_ACTION" type="redirectAction">
        <param name="actionName">s/${seoURLForRedirect}</param>
        <param name="namespace">/reports</param>
    </result>
    ...
</action>

I am setting the variable ${seoURLForRedirect} in ReportsAction before returning. I have the following mapping for the second action.

<action name="s/{seoURL}" class="ReportSeriesAction"
    method="displayReportSeries">
    ...
</action>

As you can see I have same named variable in my second action seoURL. This value is set to the value as found in the first action. I fail to understand why is the value stack still maintaining seoURL value set in the first action. Especially since I am over writing it in my redirect result params.

Any help appreciated.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Chantz
  • 5,883
  • 10
  • 56
  • 79

1 Answers1

2

Based on your class action attribute, I'm assuming you're using the Spring plugin.

Actions must be declared as scope="prototype"/non-singleton to be instantiated per-request.

If they're not, you're using a singleton, and properties will be maintained across requests.

I've never tried to set a redirectAction's actionName to a wildcard that points to another wildcarded action, so I'm not sure about the second part of the question.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Thanks Dave. I guess that explains the behavior I am seeing. I guess I will have to use some other variable. Which will be redundant code. Oh, Well. – Chantz Jan 29 '13 at 20:01
  • @Chantz Not sure what you mean; the prototype/singleton part shouldn't affect anything important. Regarding the redirectAction, I'm not saying it doesn't/won't work, I'm just saying I've never tried that. – Dave Newton Jan 29 '13 at 20:25
  • It is affecting the seoURL variable. This is present in both the first & second action. And it seems to overwrite this variable when I am immediately redirecting from the first action to the second one. Re: redirectAction, I changed my approach to use "redirect". So for now I am fine. – Chantz Jan 29 '13 at 21:37
  • @Chantz ... Struts 2 is designed to use an instance-per-request; this should not be surprising behavior. If it's set as a wildcard or parameter it'll be set on the action. – Dave Newton Jan 29 '13 at 21:39