Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.interceptor
Class MessageStoreInterceptor

    java.lang.Object
      org.apache.struts2.interceptor.MessageStoreInterceptor

All Implemented Interfaces:
  Interceptor, Serializable

    public class MessageStoreInterceptor

extends Object
implements Interceptor

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">l;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

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

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

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

Version:
  $Date: 2006-11-06 10:01:43 -0500 (Mon, 06 Nov 2006) $ $Id: MessageStoreInterceptor.java 471756 2006-11-06 15:01:43Z husted $
See Also:
  Serialized Form

Field Summary
`private static Log` | `_log`
`static String` | `actionErrorsSessionKey`
`static String` | `actionMessagesSessionKey`
`private boolean` | `allowRequestParameterSwitch`
`static String` | `fieldErrorsSessionKey`
`static String` | `NONE`
`private String` | `operationMode`
`private String` | `requestParameterSwitch`
`static String` | `RETRIEVE_MODE`
`private static long` | `serialVersionUID`
`static String` | `STORE_MODE`

Constructor Summary
`MessageStoreInterceptor()`

Method Summary
`protected void` | `after(ActionInvocation invocation, String result)` Handle the storing of field errors / action messages / field errors, which is done after action invocation, and the `operationMode` is in 'STORE'.
`protected void` | `before(ActionInvocation invocation)` Handle the retrieving of field errors / action messages / field errors, which is done before action invocation, and the `operationMode` is 'RETRIEVE'.
`void` | `destroy()` Called to let an interceptor clean up any resources it has allocated.
`boolean` | `getAllowRequestParameterSwitch()`
`String` | `getOperationModel()`
`protected String` | `getRequestOperationMode(ActionInvocation invocation)` Get the operationMode through request paramter, if `allowRequestParameterSwitch` is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor 'RETRIEVE_MODE'.
`String` | `getRequestParameterSwitch()`
`void` | `init()` Called after an interceptor is created, but before any requests are processed using `intercept` , giving the Interceptor a chance to initialize any needed resources.
`String` | `intercept(ActionInvocation invocation)` Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the `ActionInvocation` or to short-circuit the processing and just return a String return code.
`protected Collection` | `mergeCollection(Collection col1, Collection col2)` Merge `col1` and `col2` and return the composite `Collection`.
`protected Map` | `mergeMap(Map map1, Map map2)` Merge `map1` and `map2` and return the composite `Map`
`void` | `setAllowRequestParameterSwitch(boolean allowRequestParameterSwitch)`
`void` | `setOperationMode(String operationMode)`
`void` | `setRequestParameterSwitch(String requestParameterSwitch)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### serialVersionUID

    private static final long serialVersionUID

See Also:
  Constant Field Values

### _log

    private static final Log _log

### STORE_MODE

    public static final String STORE_MODE

See Also:
  Constant Field Values

### RETRIEVE_MODE

    public static final String RETRIEVE_MODE

See Also:
  Constant Field Values

### NONE

    public static final String NONE

See Also:
  Constant Field Values

### allowRequestParameterSwitch

    private boolean allowRequestParameterSwitch

### requestParameterSwitch

    private String requestParameterSwitch

### operationMode

    private String operationMode

### fieldErrorsSessionKey

    public static String fieldErrorsSessionKey

### actionErrorsSessionKey

    public static String actionErrorsSessionKey

### actionMessagesSessionKey

    public static String actionMessagesSessionKey

Constructor Detail

### MessageStoreInterceptor

    public MessageStoreInterceptor()

Method Detail

### setAllowRequestParameterSwitch

    public void setAllowRequestParameterSwitch(boolean allowRequestParameterSwitch)

### getAllowRequestParameterSwitch

    public boolean getAllowRequestParameterSwitch()

### setRequestParameterSwitch

    public void setRequestParameterSwitch(String requestParameterSwitch)

### getRequestParameterSwitch

    public String getRequestParameterSwitch()

### setOperationMode

    public void setOperationMode(String operationMode)

### getOperationModel

    public String getOperationModel()

### destroy

    public void destroy()

  Description copied from interface: `Interceptor`
  Called to let an interceptor clean up any resources it has allocated.

  Specified by:
    `destroy` in interface `Interceptor`

### init

    public void init()

  Description copied from interface: `Interceptor`
  Called after an interceptor is created, but before any requests are processed using `intercept` , giving the Interceptor a chance to initialize any needed resources.

  Specified by:
    `init` in interface `Interceptor`

### intercept

    public String intercept(ActionInvocation invocation)
                     throws Exception

  Description copied from interface: `Interceptor`
  Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the `ActionInvocation` or to short-circuit the processing and just return a String return code.

  Specified by:
    `intercept` in interface `Interceptor`
  Returns:
    the return code, either returned from `ActionInvocation.invoke()`, or from the interceptor itself.
  Throws:
    `Exception` - any system-level error, as defined in `Action.execute()`.

### before

    protected void before(ActionInvocation invocation)
                   throws Exception

  Handle the retrieving of field errors / action messages / field errors, which is done before action invocation, and the `operationMode` is 'RETRIEVE'.

  Parameters:
    `invocation` -
  Throws:
    `Exception`

### after

    protected void after(ActionInvocation invocation,
                         String result)
                  throws Exception

  Handle the storing of field errors / action messages / field errors, which is done after action invocation, and the `operationMode` is in 'STORE'.

  Parameters:
    `invocation` -
    `result` -
  Throws:
    `Exception`

### getRequestOperationMode

    protected String getRequestOperationMode(ActionInvocation invocation)

  Get the operationMode through request paramter, if `allowRequestParameterSwitch` is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor 'RETRIEVE_MODE'.

  Returns:
    String

### mergeCollection

    protected Collection mergeCollection(Collection col1,
                                         Collection col2)

  Merge `col1` and `col2` and return the composite `Collection`.

  Parameters:
    `col1` -
    `col2` -
  Returns:
    Collection

### mergeMap

    protected Map mergeMap(Map map1,
                           Map map2)

  Merge `map1` and `map2` and return the composite `Map`

  Parameters:
    `map1` -
    `map2` -
  Returns:
    Map

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.