Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Interceptors > Message Store Interceptor
Added by tm_jee, last edited by Ted Husted on Sep 10, 2006  (view change)

An interceptor to store ValidationAware action's messages / errors and field errors into Http Session, such that it will be retrieveable at a later stage. This allows the action's message / errors and field errors to be available longer that just the particular http request.

In the 'STORE' mode, the interceptor will store the ValidationAware action's message / errors and field errors into Http session.

In the 'RETRIEVE' mode, the interceptor will retrieve the stored action's message / errors and field errors and put them back into the ValidationAware action.

The interceptor does nothing in the 'NONE' mode, which is the default.

The operation mode could be switched using :-

1] Setting the iterceptor parameter eg.

  <action name="submitApplication" ...>
     <interceptor-ref name="store">
        <param name="operationMode"&gtl;STORE</param>
     </interceptor-ref>
     <interceptor-ref name="defaultStack" />
     ....
  </action>

2] Through request parameter (allowRequestParameterSwitch must be 'true' which is the default)

  // the request will have the operation mode in 'STORE'
  http://localhost:8080/context/submitApplication.action?operationMode=STORE

Parameters

  • allowRequestParameterSwitch - To enable request parameter that could switch the operation mode of this interceptor.
  • requestParameterSwitch - The request parameter that will indicate what mode this interceptor is in.
  • operationMode - The operation mode this interceptor should be in (either 'STORE', 'RETRIEVE' or 'NONE'). 'NONE' being the default.

Extending the Interceptor

The following method could be overriden :-

  • getRequestOperationMode - get the operation mode of this interceptor based on the request parameters
  • mergeCollection - merge two collections
  • mergeMap - merge two map

Examples

<action name="submitApplication" ....>
   <interceptor-ref name="store">
     <param name="operationMode">STORE</param>
   </interceptor-ref>
   <interceptor-ref name="defaultStack" />
   <result name="input" type="redirect">applicationFailed.action</result>
   <result type="dispatcher">applicationSuccess.jsp</result>
</action>

<action name="applicationFailed" ....>
   <interceptor-ref name="store">
      <param name="operationMode">RETRIEVE</param>
   </interceptor-ref>
   <result>applicationFailed.jsp</result>
</action>
With the example above, 'submitApplication.action' will have the action messages / errors / field errors stored
in the Http Session. Later when needed, (in this case, when 'applicationFailed.action' is fired, it
will get the action messages / errors / field errors stored in the Http Session and put them back into
the action.