Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 12-13.org.springframework.webflow.execution.FlowExecution


public interface FlowExecution extends FlowExecutionContext {
ViewSelection start(ExternalContext externalContext)
throws StateException;


ViewSelection signalEvent(String eventId, ExternalContext externalContext)
throws StateException;

void rehydrate(
FlowLocator flowLocator,
FlowExecutionListenerLoader listenerLoader);
}


The interface that is extended (org.springframework.webflow.FlowExecutionContext, see
Listing 12-14) provides contextual information about the executing flow.


Listing 12-14.org.springframework.webflow.FlowExecutionContext


public interface FlowExecutionContext extends FlowExecutionStatistics {
Flow getRootFlow();
Flow getActiveFlow() throws IllegalStateException;
State getCurrentState() throws IllegalStateException;
FlowSession getActiveSession() throws IllegalStateException;
}


You can see that FlowExecutionContextprovides information about the root (or top level)
flow definition, the active flow definition, the current state, and the activeSession.
It is important to understand that a FlowExecutionlasts for the entire execution of the
flow includingthe spawning of subflows.The root flow will always be the top-level flow for
which the FlowExecutionis created (in our example this would be purchase-flow). If the flow
spawns a subflow (e.g., shipping-flow) the root flow remains the same, but getActiveFlow()
now returns the subflow definition (shipping-flow).


FlowSessions


This distinction between the root flow and the active flow is modeled by org.springframework.
webflow.FlowSession. A stack of FlowSessions are maintained by FlowExecutionImpl.
In the simple case of a flow without any subflow states, there will only ever be a single
FlowSession. If a flow does contain a subflow state, then each time a subflow is spawned, the
top (active) FlowSessionis suspended, and a new FlowSessionis created and pushed onto
the stack (shown in Figure 12-2).
As you can see, there is a single FlowExecution representing the entire conversation, but
each flow that is spawned (including the parent) receives its own FlowSession. Each instance
of FlowSessionhas its own local data structure that is the basis for “flow scope.” Figure 12-2
also shows some of the statuses that a FlowSessioncan have. Table 12-4 lists all of the possible
statuses and their relevance or meaning (the statuses are defined in org.springframework.
webflow.FlowSessionStatus).


CHAPTER 12 ■ADVANCED SPRING WEB FLOW 349
Free download pdf