Spring Book – Chapter 14 – Spring MVC and Spring Web Flow

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

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

 

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

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

  • 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

  • render – this action actually renders the fragments of the next view to be presented to the client.

Page Visitors: 5807

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *