Expert Spring MVC and Web Flow

(Dana P.) #1

Flow Granularity


Flows come in varying granularities, from large top-level flows composed of many smaller
subflows to self-contained flows with no dependencies. Spring Web Flow gains much of its
power from its ability to compose multiple flows together, creating modular and reusable
application components.
Up to this point, you have seen flow definitions that are self-contained with no composi-
tion. In this section we will show you how to create modular flow definitions with subflows
and inner flows.


Subflows


A subflowis simply a flow called by another flow. Any flow can be a subflow, and any subflow is
a flow. This is possible because a flow is a coarse-grained component with a well-defined con-
tract that acts as a self-contained black box. What happens inside a flow is hidden from any
other flows, including the calling flow.


■NoteWhen a flow is spawned by another flow, the spawning flow is often referred to as the parent flow
or calling flow,while the flow being spawned is often referred to as the subflowor child flow.


Architecturally, subflows are a powerful mechanism that enable the definition of complex
flows composed of one or more subflows. Subflows can themselves contain subflows (there is
no limit to the depth of subflow nesting). Subflows are best used to model logical sequences of
steps when reuse is possible.
Consider the Purchase Product use case from Chapter 11; it contained a step to capture
product shipping information. In a real application this step could be quite complex, consisting
of different screens dependent upon the mechanism used to ship the product (air, sea, land, and
so on). You can imagine this step being reused elsewhere in the application (wherever shipping
information is required), and therefore this self-contained and reusable component is a good
candidate for refactoring into its own flow. The steps involved in refactoring logic out of an exist-
ing flow and into a subflow are as follows:


1.Isolate the web flow fragment and dependent beans to be modeled as a subflow.

2.Move the fragment and the dependent beans into their own flow definition.

3.Within the new flow definition, define an end state for every logical flow outcome. Each
end state should expose any flow attributes that are “returned” by that outcome (in this
case, the shipping information).

4.Replace the factored-out fragment in the original flow with a call to the subflow using
the subflow state.

Recall the flow definition from Chapter 11. The isolated fragment related to entering ship-
ping information is boldface. See Listing 12-5.


CHAPTER 12 ■ADVANCED SPRING WEB FLOW 337
Free download pdf