Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Web Flow
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.webflow.action
Class AbstractAction

    java.lang.Object
      org.springframework.webflow.action.AbstractAction

All Implemented Interfaces:
  org.springframework.beans.factory.InitializingBean, Action

Direct Known Subclasses:
  CompositeAction, EvaluateAction, ExternalRedirectAction, FlowDefinitionRedirectAction, MultiAction, RenderAction, SetAction, ViewFactoryActionAdapter

    public abstract class AbstractAction

extends java.lang.Object
implements Action, org.springframework.beans.factory.InitializingBean

Base action that provides assistance commonly needed by action implementations. This includes:

- 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
`protected org.apache.commons.logging.Log` | `logger` Logger, usable in subclasses.

Constructor Summary
`AbstractAction()`

Method Summary
`void` | `afterPropertiesSet()`
`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` | `error(java.lang.Exception e)` Returns an "error" result event caused by the provided exception.
`Event` | `execute(RequestContext context)` Execute this action.
`protected java.lang.String` | `getActionNameForLogging()` Internal helper to return the name of this action for logging purposes.
`EventFactorySupport` | `getEventFactorySupport()` Returns the helper delegate for creating action execution result events.
`protected void` | `initAction()` 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` | `result(java.lang.String eventId)` Returns a result event for this action with the specified identifier.
`protected Event` | `result(java.lang.String eventId, AttributeMap resultAttributes)` Returns a result event for this action with the specified identifier and the specified set of attributes.
`protected Event` | `result(java.lang.String eventId, java.lang.String resultAttributeName, java.lang.Object resultAttributeValue)` Returns a result event for this action with the specified identifier and a single attribute.
`protected Event` | `success()` Returns a "success" result event.
`protected Event` | `success(java.lang.Object result)` Returns a "success" result event with the provided result object as a parameter.
`protected Event` | `yes()` Returns a "yes" result event.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### logger

    protected final org.apache.commons.logging.Log logger

  Logger, usable in subclasses.

Constructor Detail

### AbstractAction

    public AbstractAction()

Method Detail

### getEventFactorySupport

    public EventFactorySupport getEventFactorySupport()

  Returns the helper delegate for creating action execution result events.

  Returns:
    the event factory support

### afterPropertiesSet

    public void afterPropertiesSet()
                            throws java.lang.Exception

  Specified by:
    `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
  Throws:
    `java.lang.Exception`

### initAction

    protected void initAction()
                       throws java.lang.Exception

  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:
    `java.lang.Exception`

### success

    protected Event success()

  Returns a "success" result event.

### success

    protected Event success(java.lang.Object result)

  Returns a "success" result event with the provided result object as a parameter.

  Parameters:
    `result` - the action success result

### error

    protected Event error()

  Returns an "error" result event.

### error

    protected Event error(java.lang.Exception e)

  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

    protected Event yes()

  Returns a "yes" result event.

### no

    protected Event no()

  Returns a "no" result event.

### result

    protected Event result(boolean booleanResult)

  Returns yes() if the boolean result is true, no() if false.

  Parameters:
    `booleanResult` - the boolean
  Returns:
    yes or no

### result

    protected Event result(java.lang.String eventId)

  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

    protected Event result(java.lang.String eventId,
                           AttributeMap resultAttributes)

  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 identifier
    `resultAttributes` - the event attributes
  Returns:
    the action result event

### result

    protected Event result(java.lang.String eventId,
                           java.lang.String resultAttributeName,
                           java.lang.Object resultAttributeValue)

  Returns a result event for this action with the specified identifier and a single attribute.

  Parameters:
    `eventId` - the result id
    `resultAttributeName` - the attribute name
    `resultAttributeValue` - the attribute value
  Returns:
    the action result event

### execute

    public final Event execute(RequestContext context)
                        throws java.lang.Exception

  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 access `data` 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 the next external user event is signaled. That time includes the current request plus any redirect or additional refreshes to the next view.
  - 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 interface `Action`
  Parameters:
    `context` - the action execution context, for accessing and setting data in a `scope 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:
    `java.lang.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.

### getActionNameForLogging

    protected java.lang.String 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

    protected Event doPreExecute(RequestContext context)
                          throws java.lang.Exception

  Pre-action-execution hook, subclasses may override. If this method returns a non-`null` event, the `doExecute()` 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 returns `null`, `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 the `doExecute()` will not be called, or `null` if the `doExecute()` method should be called to obtain the action result
  Throws:
    `java.lang.Exception` - an unrecoverable exception occured, either checked or unchecked

### doExecute

    protected abstract Event doExecute(RequestContext context)
                                throws java.lang.Exception

  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:
    `java.lang.Exception` - an unrecoverable exception occured, either checked or unchecked

### doPostExecute

    protected void doPostExecute(RequestContext context)
                          throws java.lang.Exception

  Post-action execution hook, subclasses may override. Will only be called if `doExecute()` was called, e.g. when `doPreExecute()` returned `null`.

  This implementation does nothing.

  Parameters:
    `context` - the action execution context, for accessing and setting data in "flow scope" or "request scope"
  Throws:
    `java.lang.Exception` - an unrecoverable exception occured, either checked or unchecked

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Web Flow
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD