A command that executes a behavior and returns a logical execution result a
calling flow execution can respond to.
Actions typically delegate down to the application (or service) layer to
perform business operations. They often retrieve data to support response
rendering. They act as a bridge between a SWF web-tier and your middle-tier
business logic layer.
When an action completes execution it signals a result event describing the
outcome of that execution (for example, "success", "error", "yes", "no",
"tryAgain", etc). In addition to providing a logical outcome the flow can
respond to, a result event may have payload associated with it, for example a
"success" return value or an "error" error code. The result event is
typically used as grounds for a state transition out of the current state of
the calling Flow.
Action implementations are often application-scoped singletons instantiated
and managed by a web-tier Spring application context to take advantage of
Spring's externalized configuration and dependency injection capabilities
(which is a form of Inversion of Control [IoC]). Actions may also be stateful
prototypes, storing conversational state as instance variables. Action
instance definitions may also be locally scoped to a specific flow definition
(see use of the "import" element of the root XML flow definition element.)
Note: Actions are directly instantiatable for use in a standalone test
environment and can be parameterized with mocks or stubs, as they are simple
POJOs. Action proxies may also be generated at runtime for delegating to POJO
business operations that have no dependency on the Spring Web Flow API.
Note: if an Action is a singleton managed in application scope, take care not
to store and/or modify caller-specific state in a unsafe manner. The Action
Action.execute(RequestContext) method runs in an independently executing
thread on each invocation so make sure you deal only with local data or
internal, thread-safe services.
Note: an Action is not a controller like a Spring MVC controller or a Struts
action is a controller. Flow actions are commands. Such commands do
not select views, they execute arbitrary behavioral logic and then return an
logical execution result. The flow that invokes an Action is responsible for
responding to the execution result to decide what to do next. In Spring Web
Flow, the flow is the controller.
author: Keith Donald author: Erwin Vervaet |