Can I propagate struts2 ActionErrors between different action classes?

Struts2 by default has a store interceptor. It stores the actionMessages, actionErrors and fieldErrors in session in STORE mode and you can retrieve the same in the next redirect by using the same interceptor by using it in RETRIEVE mode. More details can be found here


I find a better solution to pass action errors and messages on actionRedirect result type. It is working for me.

<action name="action1" class="action.Action1" >
    <result>/abc.jsp</result>
    <result name="input" type="redirectAction">
    <param name="actionName">action2</param>
    <param name="param1">${param1}</param>
    <param name="param2">${param2}</param>
    <param name="actionErrors">${actionErrors}</param>
    </result>
    </action>
    <action name="action2" class="action.Action2" >
    <result>/def.jsp</result>
    <result name="input">/def.jsp</result>
     </action/>

This is it ..... Happy coding


Basically you have to use predefined interceptors called store which takes operationMode: store and retrieve:

<package name="a" extends="struts-default" namespace="/a">
    <action name="actionA" class="actionAClass">
        <!-- Here you are storing the Error messages -->
        <interceptor-ref name="store">
            <param name="operationMode">STORE</param>
        </interceptor-ref>

        <!-- include your default stack in case you need to load other interceptors -->
        <interceptor-ref name="defaultStack" />

        <result name="input" type="redirectAction">
            <param name="actionName">actionB</param>
            <param name="namespace">/b</param>
        </result>
        <result type="redirectAction">
            <param name="actionName">actionB</param>
            <param name="namespace">/b</param>
        </result>
    </action>
</package>
<package name="b" extends="struts-default" namespace="/b">
    <action name="actionB" class="actionBClass">

        <interceptor-ref name="store">
            <param name="operationMode">RETRIEVE</param>
        </interceptor-ref>

        <!-- include your default stack in case you need to load other interceptors -->
        <interceptor-ref name="defaultStack" />

        <result>/foo.jsp</result>
    </action>
</package>

There may be a way to do that, but I don't think it's a very good way to use struts. If actionA is failing validation, you most likely would want to either have a non-redirect input result for it that shows the errors, or perhaps a global error page that can show it.

I suppose you could store the action errors somewhere like the session in between the redirect, but you wouldn't really be using the framework how it was designed.