org.apache.struts2.interceptor
Class MessageStoreInterceptor

java.lang.Object
  extended by org.apache.struts2.interceptor.MessageStoreInterceptor
All Implemented Interfaces:
Interceptor, java.io.Serializable

public class MessageStoreInterceptor
extends java.lang.Object
implements Interceptor

An interceptor to store a 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.

In the 'AUTOMATIC' mode, the interceptor will always retrieve the stored action's message / errors and field errors and put them back into the ValidationAware action, and after Action execution, if the Result is an instance of ServletRedirectResult, the action's message / errors and field errors into automatically be stored in the HTTP session..

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

The following method could be overriden :-

 

 <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: 2009-04-27 04:09:35 +0200 (Mon, 27 Apr 2009) $ $Id: MessageStoreInterceptor.java 768855 2009-04-27 02:09:35Z wesw $
See Also:
Serialized Form

Field Summary
static java.lang.String actionErrorsSessionKey
           
static java.lang.String actionMessagesSessionKey
           
static java.lang.String AUTOMATIC_MODE
           
static java.lang.String fieldErrorsSessionKey
           
static java.lang.String NONE
           
static java.lang.String RETRIEVE_MODE
           
static java.lang.String STORE_MODE
           
 
Constructor Summary
MessageStoreInterceptor()
           
 
Method Summary
protected  void after(ActionInvocation invocation, java.lang.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()
           
 boolean getAllowRequestParameterSwitch()
           
 java.lang.String getOperationModel()
           
protected  java.lang.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'.
 java.lang.String getRequestParameterSwitch()
           
 void init()
           
 java.lang.String intercept(ActionInvocation invocation)
           
protected  java.util.Collection mergeCollection(java.util.Collection col1, java.util.Collection col2)
          Merge col1 and col2 and return the composite Collection.
protected  java.util.Map mergeMap(java.util.Map map1, java.util.Map map2)
          Merge map1 and map2 and return the composite Map
 void setAllowRequestParameterSwitch(boolean allowRequestParameterSwitch)
           
 void setOperationMode(java.lang.String operationMode)
           
 void setRequestParameterSwitch(java.lang.String requestParameterSwitch)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTOMATIC_MODE

public static final java.lang.String AUTOMATIC_MODE
See Also:
Constant Field Values

STORE_MODE

public static final java.lang.String STORE_MODE
See Also:
Constant Field Values

RETRIEVE_MODE

public static final java.lang.String RETRIEVE_MODE
See Also:
Constant Field Values

NONE

public static final java.lang.String NONE
See Also:
Constant Field Values

fieldErrorsSessionKey

public static final java.lang.String fieldErrorsSessionKey
See Also:
Constant Field Values

actionErrorsSessionKey

public static final java.lang.String actionErrorsSessionKey
See Also:
Constant Field Values

actionMessagesSessionKey

public static final java.lang.String actionMessagesSessionKey
See Also:
Constant Field Values
Constructor Detail

MessageStoreInterceptor

public MessageStoreInterceptor()
Method Detail

setAllowRequestParameterSwitch

public void setAllowRequestParameterSwitch(boolean allowRequestParameterSwitch)

getAllowRequestParameterSwitch

public boolean getAllowRequestParameterSwitch()

setRequestParameterSwitch

public void setRequestParameterSwitch(java.lang.String requestParameterSwitch)

getRequestParameterSwitch

public java.lang.String getRequestParameterSwitch()

setOperationMode

public void setOperationMode(java.lang.String operationMode)

getOperationModel

public java.lang.String getOperationModel()

destroy

public void destroy()
Specified by:
destroy in interface Interceptor

init

public void init()
Specified by:
init in interface Interceptor

intercept

public java.lang.String intercept(ActionInvocation invocation)
                           throws java.lang.Exception
Specified by:
intercept in interface Interceptor
Throws:
java.lang.Exception

before

protected void before(ActionInvocation invocation)
               throws java.lang.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:
java.lang.Exception

after

protected void after(ActionInvocation invocation,
                     java.lang.String result)
              throws java.lang.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:
java.lang.Exception

getRequestOperationMode

protected java.lang.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 java.util.Collection mergeCollection(java.util.Collection col1,
                                               java.util.Collection col2)
Merge col1 and col2 and return the composite Collection.

Parameters:
col1 -
col2 -
Returns:
Collection

mergeMap

protected java.util.Map mergeMap(java.util.Map map1,
                                 java.util.Map map2)
Merge map1 and map2 and return the composite Map

Parameters:
map1 -
map2 -
Returns:
Map


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