Class AbstractAction
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
,Action
- Direct Known Subclasses:
CompositeAction
,EvaluateAction
,ExternalRedirectAction
,FlowDefinitionRedirectAction
,MultiAction
,RenderAction
,SetAction
,ViewFactoryActionAdapter
- Implementing
InitializingBean
to receive an init callback when deployed within a Spring bean factory. - Exposing convenient event factory methods to create common result
Event
objects such as "success" and "error". - A hook for inserting action pre and post execution logic.
- Author:
- Keith Donald, Erwin Vervaet
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.apache.commons.logging.Log
Logger, usable in subclasses. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
protected abstract Event
doExecute
(RequestContext context) Template hook method subclasses should override to encapsulate their specific action execution logic.protected void
doPostExecute
(RequestContext context) Post-action execution hook, subclasses may override.protected Event
doPreExecute
(RequestContext context) Pre-action-execution hook, subclasses may override.protected Event
error()
Returns an "error" result event.protected Event
Returns an "error" result event caused by the provided exception.final Event
execute
(RequestContext context) Execute this action.protected String
Internal helper to return the name of this action for logging purposes.Returns the helper delegate for creating action execution result events.protected void
Action initializing callback, may be overridden by subclasses to perform custom initialization logic.protected Event
no()
Returns a "no" result event.protected Event
result
(boolean booleanResult) Returns yes() if the boolean result is true, no() if false.protected Event
Returns a result event for this action with the specified identifier.protected Event
Returns a result event for this action with the specified identifier and a single attribute.protected Event
result
(String eventId, AttributeMap<Object> resultAttributes) Returns a result event for this action with the specified identifier and the specified set of attributes.protected Event
success()
Returns a "success" result event.protected Event
Returns a "success" result event with the provided result object as a parameter.protected Event
yes()
Returns a "yes" result event.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log loggerLogger, usable in subclasses.
-
-
Constructor Details
-
AbstractAction
public AbstractAction()
-
-
Method Details
-
getEventFactorySupport
Returns the helper delegate for creating action execution result events.- Returns:
- the event factory support
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
initAction
Action initializing callback, may be overridden by subclasses to perform custom initialization logic.Keep in mind that this hook will only be invoked when this action is deployed in a Spring application context since it uses the Spring
InitializingBean
mechanism to trigger action initialisation.- Throws:
Exception
-
success
Returns a "success" result event. -
success
Returns a "success" result event with the provided result object as a parameter.- Parameters:
result
- the action success result
-
error
Returns an "error" result event. -
error
Returns an "error" result event caused by the provided exception.- Parameters:
e
- the exception that caused the error event, to be configured as an event attribute
-
yes
Returns a "yes" result event. -
no
Returns a "no" result event. -
result
Returns yes() if the boolean result is true, no() if false.- Parameters:
booleanResult
- the boolean- Returns:
- yes or no
-
result
Returns a result event for this action with the specified identifier. Typically called as part of return, for example:protected Event doExecute(RequestContext context) { // do some work if (some condition) { return result("success"); } else { return result("error"); } }
Consider calling the error() or success() factory methods for returning common results.- Parameters:
eventId
- the result event identifier- Returns:
- the action result event
-
result
Returns a result event for this action with the specified identifier and the specified set of attributes. Typically called as part of return, for example:protected Event doExecute(RequestContext context) { // do some work AttributeMap resultAttributes = new AttributeMap(); resultAttributes.put("name", "value"); if (some condition) { return result("success", resultAttributes); } else { return result("error", resultAttributes); } }
Consider calling the error() or success() factory methods for returning common results.- Parameters:
eventId
- the result event identifierresultAttributes
- the event attributes- Returns:
- the action result event
-
result
Returns a result event for this action with the specified identifier and a single attribute.- Parameters:
eventId
- the result idresultAttributeName
- the attribute nameresultAttributeValue
- the attribute value- Returns:
- the action result event
-
execute
Description copied from interface:Action
Execute this action. Action execution will occur in the context of a request associated with an active flow execution.Action invocation is typically triggered in a production environment by a state within a flow carrying out the execution of a flow definition. The result of action execution, a logical outcome event, can be used as grounds for a transition out of the calling state.
Note: The
RequestContext
argument to this method provides access to data about the active flow execution in the context of the currently executing thread. Among other things, this allows this action to accessdata
set by other actions, as well as set its own attributes it wishes to expose in a given scope.Some notes about actions and their usage of the attribute scope types:
- Attributes set in
request scope
exist for the life of the currently executing request only. - Attributes set in
flash scope
exist until after view rendering is completed. That time includes the current request plus any redirect required for the view render to complete. - Attributes set in
flow scope
exist for the life of the flow session and will be cleaned up automatically when the flow session ends. - Attributes set in
conversation scope
exist for the life of the entire flow execution representing a single logical "conversation" with a user.
All attributes present in any scope are typically exposed in a model for access by a view when an "interactive" state type such as a view state is entered.
Note: flow scope should generally not be used as a general purpose cache, but rather as a context for data needed locally by other states of the flow this action participates in. For example, it would be inappropriate to stuff large collections of objects (like those returned to support a search results view) into flow scope. Instead, put such result collections in request scope, and ensure you execute this action again each time you wish to view those results. 2nd level caches managed outside of SWF are more general cache solutions.
Note: as flow scoped attributes are eligible for serialization they should be
Serializable
.- Specified by:
execute
in interfaceAction
- Parameters:
context
- the action execution context, for accessing and setting data in ascope type
, as well as obtaining other flow contextual information (e.g. request context attributes and flow execution context information)- Returns:
- a logical result outcome, used as grounds for a transition in the calling flow (e.g. "success", "error", "yes", "no", * ...)
- Throws:
Exception
- a exception occurred during action execution, either checked or unchecked; note, any recoverable exceptions should be caught within this method and an appropriate result outcome returned or be handled by the current state of the calling flow execution.
- Attributes set in
-
getActionNameForLogging
Internal helper to return the name of this action for logging purposes. Defaults to the short class name.- See Also:
-
ClassUtils.getShortName(java.lang.Class)
-
doPreExecute
Pre-action-execution hook, subclasses may override. If this method returns a non-null
event, thedoExecute()
method will not be called and the returned event will be used to select a transition to trigger in the calling action state. If this method returnsnull
,doExecute()
will be called to obtain an action result event.This implementation just returns
null
.- Parameters:
context
- the action execution context, for accessing and setting data in "flow scope" or "request scope"- Returns:
- the non-
null
action result, in which case thedoExecute()
will not be called, ornull
if thedoExecute()
method should be called to obtain the action result - Throws:
Exception
- an unrecoverable exception occured, either checked or unchecked
-
doExecute
Template hook method subclasses should override to encapsulate their specific action execution logic.- Parameters:
context
- the action execution context, for accessing and setting data in "flow scope" or "request scope"- Returns:
- the action result event
- Throws:
Exception
- an unrecoverable exception occured, either checked or unchecked
-
doPostExecute
Post-action execution hook, subclasses may override. Will only be called ifdoExecute()
was called, e.g. whendoPreExecute()
returnednull
.This implementation does nothing.
- Parameters:
context
- the action execution context, for accessing and setting data in "flow scope" or "request scope"- Throws:
Exception
- an unrecoverable exception occured, either checked or unchecked
-