■Tip It may be helpful to think of a flow as a method call, just one that can span many requests into the
server. Following this analogy, top-level flows would be public, while inline flows would be private.
Managing FlowExecutions
In this section we will look in detail at the life cycle of a FlowExecutionfrom start to end and
learn how that life cycle is managed. Before discussing how a FlowExecutionis created, it is
worth reviewing how Spring Web Flow is integrated into the various web frameworks.
Integration with Web Frameworks
Chapter 11 introduced the definition of a flow and discussed briefly how FlowExecutions are
managed. In this section we will delve into the FlowExecutionManager, the central façade for
driving the execution of flows,and examine what happens behind the scenes.
Essentially, the FlowExecutionManageris the primary façade through which other systems
like Spring MVC communicate with Spring Web Flow. If Spring Web Flow is a proverbial black
box, then FlowExecutionManageris the lid.
This “handover” to Spring Web Flow is accomplished by calling either the
FlowExecutionManager.launch() orFlowExecutionManager.signalEvent() method, which
instructs Spring Web Flow to initiate processing of an external user event. The launch opera-
tion instructs Web Flow to launch an entirely new flow execution (or user conversation),
and the signalEventoperation instructs Web Flow to signal a user event against the current
state of an existing flow execution. Both methods accept org.springframework.webflow.
ExternalContextand return org.springframework.webflow.ViewSelection. Listing 12-11
shows the ExternalContextinterface façade.
Listing 12-11.Implementation of org.springframework.webflow.ExternalContext
public interface ExternalContext {
Map getRequestParameterMap();
Map getRequestMap();
SharedMap getSessionMap();
SharedMap getApplicationMap();
public interface SharedMap extends Map {
public Object getMutex();
}
}
The ExternalContextinterface enables Spring Web Flow artifacts such as actions to access
information about the calling environment in a standard, normalized fashion, without coupling
those artifacts to a specific deployment environment. It is up to a system calling into Spring
Web Flow to provide an appropriate ExternalContextimplementation. This implementation
may provide access to environment-specific constructs; for example, the servlet-specific
ExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext)
provides access to the native HttpServletRequestand HttpServletResponseServlet artifacts.
Table 12-2 provides a list of ExternalContextadapters provided by Spring Web Flow.
346 CHAPTER 12 ■ADVANCED SPRING WEB FLOW