10. Variable Scopes
Web Flow can store variables in one of several scopes:
10.1. Flow Scope
Flow scope gets allocated when a flow starts and destroyed when the flow ends. With the default implementation, any objects stored in flow scope need to be serializable.
10.2. View Scope
View scope gets allocated when a view-state
enters and destroyed when the state exits.
View scope is referenceable only from within a view-state
.
With the default implementation, any objects stored in view scope need to be serializable.
10.3. Request Scope
Request scope gets allocated when a flow is called and destroyed when the flow returns.
10.4. Flash Scope
Flash scope gets allocated when a flow starts, cleared after every view render, and destroyed when the flow ends. With the default implementation, any objects stored in flash scope need to be serializable.
10.5. Conversation Scope
Conversation scope gets allocated when a top-level flow starts and gets destroyed when the top-level flow ends. Conversation scope is shared by a top-level flow and all of its sub-flows. With the default implementation, conversation-scoped objects are stored in the HTTP session and should generally be serializable to account for typical session replication.
10.6. Choosing a Scope
The scope to use is often determined contextually — for example, depending on where a variable is defined: at the start of the flow definition (flow scope), inside a a view state (view scope), and so on. In other cases (for example, in EL expressions and Java code), you must specify it explicitly. Subsequent sections explain how this is done.