Spring Web Flow

org.springframework.webflow.execution
Interface RequestContext

All Known Subinterfaces:
RequestControlContext
All Known Implementing Classes:
MockRequestContext, MockRequestControlContext

public interface RequestContext

A context for a single request to manipulate a flow execution. Allows Web Flow users to access contextual information about the executing request, as well as the governing active flow execution.

The term request is used to describe a single call (thread) into the flow system by an external actor to manipulate exactly one flow execution.

A new instance of this object is typically created when one of the core operations supported by a flow execution is invoked, either start to launch the flow execution, signalEvent to resume the flow execution, or refresh to reconstitute the flow execution's last view selection for purposes of reissuing a user response.

Once created this context object is passed around throughout flow execution request processing where it may be accessed and reasoned upon by SWF-internal artifacts such as states, user-implemented action code, and state transition criteria.

When a call into a flow execution returns this object goes out of scope and is disposed of automatically. Thus a request context is an internal artifact used within a FlowExecution: this object is not exposed to external client code, e.g. a view implementation (JSP).

The requestScope property may be used as a store for arbitrary data that should exist for the life of this object.

The web flow system will ensure that a RequestContext object is local to the current thread. It can be safely manipulated without needing to worry about concurrent access.

Note: this request context is in no way linked to an HTTP or Portlet request. It uses the familiar "request" naming convention to indicate a single call to manipulate a runtime execution of a flow definition.

Author:
Keith Donald, Erwin Vervaet

Method Summary
 FlowDefinition getActiveFlow()
          Returns the definition of the flow that is currently executing.
 MutableAttributeMap<java.lang.Object> getAttributes()
          Returns a context map for accessing attributes about the state of the current request.
 MutableAttributeMap<java.lang.Object> getConversationScope()
          Returns a mutable accessor for accessing and/or setting attributes in conversation scope.
 Event getCurrentEvent()
          Returns the current event being processed by this flow.
 StateDefinition getCurrentState()
          Returns the current state of the executing flow.
 TransitionDefinition getCurrentTransition()
          Returns the current transition executing in this request.
 View getCurrentView()
          Returns the current view in use; if not null, the view returned is about to be rendered, is rendering, is processing a user event, or has finished user event processing and the current ViewState is exiting due to a state transition.
 ExternalContext getExternalContext()
          Returns the external client context that originated (or triggered) this request.
 MutableAttributeMap<java.lang.Object> getFlashScope()
          Returns a mutable map for accessing and/or setting attributes in flash scope.
 FlowExecutionContext getFlowExecutionContext()
          Returns contextual information about the flow execution itself.
 java.lang.String getFlowExecutionUrl()
          Returns the URL of this flow execution.
 MutableAttributeMap<java.lang.Object> getFlowScope()
          Returns a mutable map for accessing and/or setting attributes in flow scope.
 TransitionDefinition getMatchingTransition(java.lang.String eventId)
          Returns the transition that would execute on the occurrence of the given event.
 MessageContext getMessageContext()
          Returns the message context of this request.
 ParameterMap getRequestParameters()
          Returns the immutable input parameters associated with this request into Spring Web Flow.
 MutableAttributeMap<java.lang.Object> getRequestScope()
          Returns a mutable map for accessing and/or setting attributes in request scope.
 MutableAttributeMap<java.lang.Object> getViewScope()
          Returns a mutable map for accessing and/or setting attributes in view scope.
 boolean inViewState()
          Returns true if the flow is currently active and in a view state.
 

Method Detail

getActiveFlow

FlowDefinition getActiveFlow()
                             throws java.lang.IllegalStateException
Returns the definition of the flow that is currently executing.

Returns:
the flow definition for the active session
Throws:
java.lang.IllegalStateException - if the flow execution is not active
See Also:
FlowExecutionContext.isActive()

getCurrentState

StateDefinition getCurrentState()
                                throws java.lang.IllegalStateException
Returns the current state of the executing flow. Returns null if the active flow's start state has not yet been entered.

Returns:
the current state, or null if in the process of starting
Throws:
java.lang.IllegalStateException - if this flow execution is not active
See Also:
FlowExecutionContext.isActive()

getMatchingTransition

TransitionDefinition getMatchingTransition(java.lang.String eventId)
                                           throws java.lang.IllegalStateException
Returns the transition that would execute on the occurrence of the given event.

Parameters:
eventId - the id of the user event
Returns:
the transition that would trigger, or null if no transition matches
Throws:
java.lang.IllegalStateException - if this flow execution is not active
See Also:
FlowExecutionContext.isActive()

inViewState

boolean inViewState()
Returns true if the flow is currently active and in a view state. When in a view state getViewScope(), can be safely called.

Returns:
true if in a view state, false if not
See Also:
getViewScope()

getRequestScope

MutableAttributeMap<java.lang.Object> getRequestScope()
Returns a mutable map for accessing and/or setting attributes in request scope. Request scoped attributes exist for the duration of this request only.

Returns:
the request scope

getFlashScope

MutableAttributeMap<java.lang.Object> getFlashScope()
Returns a mutable map for accessing and/or setting attributes in flash scope. Flash scoped attributes exist until the next event is signaled in the flow execution.

Returns:
the flash scope

getViewScope

MutableAttributeMap<java.lang.Object> getViewScope()
                                                   throws java.lang.IllegalStateException
Returns a mutable map for accessing and/or setting attributes in view scope. View scoped attributes exist for the life of the current view state.

Returns:
the view scope
Throws:
java.lang.IllegalStateException - if this flow is not in a view-state or the flow execution is not active
See Also:
inViewState(), FlowExecutionContext.isActive()

getFlowScope

MutableAttributeMap<java.lang.Object> getFlowScope()
                                                   throws java.lang.IllegalStateException
Returns a mutable map for accessing and/or setting attributes in flow scope. Flow scoped attributes exist for the life of the active flow session.

Returns:
the flow scope
Throws:
java.lang.IllegalStateException - if the flow execution is not active
See Also:
FlowSession, FlowExecutionContext.isActive()

getConversationScope

MutableAttributeMap<java.lang.Object> getConversationScope()
Returns a mutable accessor for accessing and/or setting attributes in conversation scope. Conversation scoped attributes exist for the life of the executing flow and are shared across all flow sessions.

Returns:
the conversation scope
See Also:
FlowExecutionContext

getRequestParameters

ParameterMap getRequestParameters()
Returns the immutable input parameters associated with this request into Spring Web Flow. The map returned is immutable and cannot be changed.

This is typically a convenient shortcut for accessing the ExternalContext.getRequestParameterMap() directly.

See Also:
getExternalContext()

getExternalContext

ExternalContext getExternalContext()
Returns the external client context that originated (or triggered) this request.

Acting as a facade, the returned context object provides a single point of access to the calling client's environment. It provides normalized access to attributes of the client environment without tying you to specific constructs within that environment.

In addition, this context may be downcastable to a specific context type for a specific client environment, such as Servlets or Portlets. Such downcasting will give you full access to a native HttpServletRequest, for example. With that said, for portability reasons you should avoid coupling your flow artifacts to a specific deployment environment when possible.

Returns:
the originating external context, the one that triggered the current execution request

getMessageContext

MessageContext getMessageContext()
Returns the message context of this request. Useful for recording messages during the course of flow execution for display to the client.

Returns:
the message context

getFlowExecutionContext

FlowExecutionContext getFlowExecutionContext()
Returns contextual information about the flow execution itself. Information in this context typically spans more than one request.

Returns:
the flow execution context

getCurrentEvent

Event getCurrentEvent()
Returns the current event being processed by this flow. The event may or may not have caused a state transition to happen.

Returns:
the current event, or null if no event has been signaled yet

getCurrentTransition

TransitionDefinition getCurrentTransition()
Returns the current transition executing in this request.

Returns:
the current transition, or null if no transition has occurred yet

getCurrentView

View getCurrentView()
Returns the current view in use; if not null, the view returned is about to be rendered, is rendering, is processing a user event, or has finished user event processing and the current ViewState is exiting due to a state transition. Returns null if the flow is not in a view state.

Returns:
the current view, or null if the flow is not in a view state

getAttributes

MutableAttributeMap<java.lang.Object> getAttributes()
Returns a context map for accessing attributes about the state of the current request. These attributes may be used to influence flow execution behavior.

Returns:
the current attributes of this request, or empty if none are set

getFlowExecutionUrl

java.lang.String getFlowExecutionUrl()
                                     throws java.lang.IllegalStateException
Returns the URL of this flow execution. Needed by response writers that write out the URL of this flow execution to allow calling back this execution in a subsequent request.

Returns:
the flow execution URL
Throws:
java.lang.IllegalStateException - if the flow execution has not yet had its key assigned

Spring Web Flow