public class MessageStoreInterceptor extends AbstractInterceptor
An interceptor to store a ValidationAware
action's messages / errors and field errors into
HTTP Session, such that it will be retrievable at a later stage. This allows the action's message /
errors and field errors to be available longer that just the particular HTTP request.
If no session exists, nothing will be stored and can be retrieved later. In other terms, the application is responsible to open the session.
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 interceptor 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 overridden:
<action name="submitApplication" ....> <interceptor-ref name="store"> <param name="operationMode">aSTORE</param> </interceptor-ref> <interceptor-ref name="defaultStack" /> <result name="input" type="redirect">aapplicationFailed.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.
Modifier and Type | Field and Description |
---|---|
static String |
actionErrorsSessionKey |
static String |
actionMessagesSessionKey |
static String |
AUTOMATIC_MODE |
static String |
fieldErrorsSessionKey |
static String |
NONE |
static String |
RETRIEVE_MODE |
static String |
STORE_MODE |
Constructor and Description |
---|
MessageStoreInterceptor() |
Modifier and Type | Method and Description |
---|---|
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'. |
protected MessageStorePreResultListener |
createPreResultListener(ActionInvocation invocation) |
boolean |
getAllowRequestParameterSwitch() |
String |
getOperationModel() |
protected String |
getRequestOperationMode(ActionInvocation invocation)
Get the operationMode through request parameter, if
allowRequestParameterSwitch
is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor
'RETRIEVE_MODE'. |
String |
getRequestParameterSwitch() |
String |
intercept(ActionInvocation invocation)
Override to handle interception
|
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) |
destroy, init
public static final String AUTOMATIC_MODE
public static final String STORE_MODE
public static final String RETRIEVE_MODE
public static final String NONE
public static final String fieldErrorsSessionKey
public static final String actionErrorsSessionKey
public static final String actionMessagesSessionKey
public void setAllowRequestParameterSwitch(boolean allowRequestParameterSwitch)
public boolean getAllowRequestParameterSwitch()
public void setRequestParameterSwitch(String requestParameterSwitch)
public String getRequestParameterSwitch()
public void setOperationMode(String operationMode)
public String getOperationModel()
public String intercept(ActionInvocation invocation) throws Exception
AbstractInterceptor
intercept
in interface Interceptor
intercept
in class AbstractInterceptor
invocation
- the action invocationActionInvocation.invoke()
, or from the interceptor itself.Exception
- any system-level error, as defined in Action.execute()
.protected MessageStorePreResultListener createPreResultListener(ActionInvocation invocation)
protected void before(ActionInvocation invocation) throws Exception
operationMode
is 'RETRIEVE'.invocation
- the action invocationException
- in case of any errorprotected String getRequestOperationMode(ActionInvocation invocation)
allowRequestParameterSwitch
is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor
'RETRIEVE_MODE'.invocation
- the action invocationprotected Collection mergeCollection(Collection col1, Collection col2)
col1
and col2
and return the composite
Collection
.col1
- first collectioncol2
- second collectionCopyright © 2000–2020 Apache Software Foundation. All rights reserved.