Class MessageStoreInterceptor
- All Implemented Interfaces:
Serializable
,ConditionalInterceptor
,Interceptor
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
- 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', 'AUTOMATIC', or 'NONE'). 'NONE' being the default.
The following method could be overridden:
- 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">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.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
before
(ActionInvocation invocation) Handle the retrieving of field errors / action messages / field errors, which is done before action invocation, and theoperationMode
is 'RETRIEVE'.protected MessageStorePreResultListener
createPreResultListener
(ActionInvocation invocation) boolean
protected String
getRequestOperationMode
(ActionInvocation invocation) Get the operationMode through request parameter, ifallowRequestParameterSwitch
is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor 'RETRIEVE_MODE'.intercept
(ActionInvocation invocation) Override to handle interceptionprotected Collection
mergeCollection
(Collection col1, Collection col2) Mergecol1
andcol2
and return the compositeCollection
.protected Map
Mergemap1
andmap2
and return the compositeMap
void
setAllowRequestParameterSwitch
(boolean allowRequestParameterSwitch) void
setOperationMode
(String operationMode) void
setRequestParameterSwitch
(String requestParameterSwitch) Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptor
destroy, init, setDisabled, shouldIntercept
-
Field Details
-
AUTOMATIC_MODE
- See Also:
-
STORE_MODE
- See Also:
-
RETRIEVE_MODE
- See Also:
-
NONE
- See Also:
-
fieldErrorsSessionKey
- See Also:
-
actionErrorsSessionKey
- See Also:
-
actionMessagesSessionKey
- See Also:
-
-
Constructor Details
-
MessageStoreInterceptor
public MessageStoreInterceptor()
-
-
Method Details
-
setAllowRequestParameterSwitch
public void setAllowRequestParameterSwitch(boolean allowRequestParameterSwitch) -
getAllowRequestParameterSwitch
public boolean getAllowRequestParameterSwitch() -
setRequestParameterSwitch
-
getRequestParameterSwitch
-
setOperationMode
-
getOperationModel
-
intercept
Description copied from class:AbstractInterceptor
Override to handle interception- Specified by:
intercept
in interfaceInterceptor
- Specified by:
intercept
in classAbstractInterceptor
- Parameters:
invocation
- the action invocation- Returns:
- the return code, either returned from
ActionInvocation.invoke()
, or from the interceptor itself. - Throws:
Exception
- any system-level error, as defined inAction.execute()
.
-
createPreResultListener
-
before
Handle the retrieving of field errors / action messages / field errors, which is done before action invocation, and theoperationMode
is 'RETRIEVE'.- Parameters:
invocation
- the action invocation- Throws:
Exception
- in case of any error
-
getRequestOperationMode
Get the operationMode through request parameter, ifallowRequestParameterSwitch
is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor 'RETRIEVE_MODE'.- Parameters:
invocation
- the action invocation- Returns:
- the request operation mode
-
mergeCollection
Mergecol1
andcol2
and return the compositeCollection
.- Parameters:
col1
- first collectioncol2
- second collection- Returns:
- the merged collection
-
mergeMap
Mergemap1
andmap2
and return the compositeMap
- Parameters:
map1
- first mapmap2
- second map- Returns:
- the merged map
-