struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Lindholm <greg.lindh...@gmail.com>
Subject Re: Passing values from one Action to Other
Date Tue, 03 Nov 2009 21:11:36 GMT
On Tue, Nov 3, 2009 at 3:50 PM, james billa <jambilla@gmail.com> wrote:

> 1 . Using struts (2.1.6) how would you pass values from one action to
> another other than keeping them in model? Is there any other way?
>
>
You can either pass them as parameters or stuff them in the session.

Parameters:
      <result type="redirectAction">
        <param name="actionName">MyAction</param>
        <param name="p1">${p1}</param>
        <param name="p2">${p2}</param>
        <param name="p3">${p3}</param>
      </result>
Just need to setup getters for the parameters (getP1(), getP2(), etc.) in
your action.
You do have a limit on how much you can pass and all the parameters must be
Strings (or convertable to String).


> 2. I am redirecting one action to second action using type="redirect".
> Version Struts 2.1.6. Below is the xml code. If I set some
> actionerrors/fielderros in MyAction (first action), they are lost while
> executing second action and not appearing in my jsp "PageDisplay". So when
> we do a redirect, how do I carry forwrd the action errors from action1 to
> page (action2 should also be executed)? You may ask me whey would I execute
> second action when the first one has error? It depends on the type of error
> I get in action1, for some of the action erros that I set, still I need to
> execute the second action and display the first action error message in the
> jsp.
>

You can use this [1] *RedirectMessageInterceptor *

[1]
http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/


>
> Below is the xml code.
>
> <action name="MyAction1" class="com.abc.xyz.MyAction">
> <interceptor-ref name="myStack" />
> <result name="success" type="redirect">YourAction</result>
>

You probably mean redirectAction


> </action>
>
> <action name="YourAction1" class="com.abc.xyz.YourAction">
> <interceptor-ref name="myStack" />
> <result name="success" type="tiles">PageDisplay</result>
> </action>
>
> Thanks,
> JB
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message