Flow Scopes
While defining flows, you can define variables. Variables are always defined with a scope attached to it and it always exists in that scope as well. The scope of a variable actually defines the context and the time-frame the variable and its value exists. The various scopes available in Spring Web Flow can be summarized as shown in Table 14-4 below.
Table 14-4. Spring Web Flow scopes
Scope | Scope Variable | Description |
Conversation | conversationScope | Global execution scope and exists in current flow and all sub-flows. |
Flow | flowScope | Lasts for the life of the current flow. |
Flash | flashScope | Exists in the current view and next view. It is cleaned up after the next view is rendered. |
View | viewScope | Associated with each view-state. Exists for current view including refreshes. |
Request | requestScope | Exists for current HTTP request and lasts only for this request. |
It’s important to note that scopes are being searched in a particular order. The order is as shown in the above table with the “Request” scope being searched first and “Conversation” scope being searched the last.
Flow Executor
Flow Executor is the entry-point into the Spring Web Flow system and is responsible for managing the starting and resuming of a typical Spring Web Flow. Default configuration of Flow Executor is very simple and is as shown in Listing 14-28 below.
Listing 14-28. Flow Executor configuration
1 2 3 |
… <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/> … |
For debugging purposes you can explicitly configure the Flow Executor so as to observe the execution of a typical life-cycle of a flow in contention. You also have a provision to define custom flow execution listeners as shown in Listing 14-29 below.
Listing 14-29. Configuring flow execution listener
1 2 3 4 5 6 7 |
… <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"> <webflow:flow-execution-listeners> <webflow:listener ref="sampleFlowExecutionListener"/> </webflow:flow-execution-listeners> </webflow:flow-executor> … |
Interface org.springframework.webflow.executor.FlowExecutor is the entry-point service interface in Spring Web Flow and the definition is as shown in Listing 14-30 below.
Listing 14-30. Definition of FlowExecutor interface in Spring Web Flow
1 2 3 4 5 6 7 8 |
package org.springframework.webflow.executor; public interface FlowExecutor { FlowExecutionResult launchExecution(String flowId, MutableAttributeMap input, Ex ternalContext context) throws FlowException; FlowExecutionResult resumeExecution(String flowExecutionKey, ExternalContext con text) throws FlowException; } |
Flow Action
The flow action is responsible for executing a particular behavior at various points within a Spring flow. There are various defined points during which an action can be executed like on startup, before rendering etc. There are three types of flow actions which can be summarized as below:
- evaluate – this action evaluates the expressions used. Listing 14-31 below shows declaring “evaluate” for evaluating an expression. It has capability of resolving properties on scoped beans and also has the capability of invoking methods and can assign the evaluated values as required. It can also optionally perform a result type conversion as needed which is very convenient to the developers.
Listing 14-31. Using “evaluate” to evaluate an expression
1 |
<evaluate expression="calculateLoyaltyPoints(customerCode)"/> |
- set – this action sets the evaluated value to the variable. Listing 14-32 below shows declaring “set” and using it in the configuration.
Listing 14-32. Using “set” to set value to the variable
1 |
<set name="flowScope.customerCode" value="requestParameters.customerCode"/> |
- render – this action actually renders the fragments of the next view to be presented to the client.
Page Visitors: 7466

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023