Flow
A flow can be considered as a task which a user wishes to perform in your web application like BookCargo, GetLoyaltyPoints etc. to name a few. The flow can consists of several steps grouped together to achieve a task as a whole. In Listing 14-21 below shows declaration of a typical Web Flow in the configuration file of Spring Web Flow.
Listing 14-21. Declaration of a sample Web Flow in configuration file
1 2 3 4 5 6 7 8 9 |
<flow …> <view-state id="enterShipmentDetails"> <transition on="calculate" to="showLoyaltyPoints"/> </view-state> <view-state id="showLoyaltyPoints"> <transition on="submit" to="bookingConfirmation"/> </view-state> <view-state id="bookingConfirmation"/> </flow> |
A flow consists of following elements as summarized below:
- States – the steps in a typical flow. There are various states which a flow can have as summarized below:
- View State – used to display useful information to the user. The actual view implementation can be anything which the Spring MVC framework supports. View state is declared as shown in Listing 14-22 below.
Listing 14-22. Declaring view state in Spring Web Flow
1 |
<view-state id="welcome" view="welcome" /> |
- Action State – state where the actual work happens. In this state the method in the Spring managed bean is called where the actual work happens. Listing 14-23 below shows the declaration of action state.
Listing 14-23. Declaring action state in Spring Web Flow
1 2 3 4 |
<action-state id="saveBooking"> <evaluate expression="…" /> <transition to="bookingConfirmation" /> </action-state> |
- Decision State – state where according to decision it can branch out and flow in a different direction. Listing 14-24 below shows the declaration of decision state in the Spring Web Flow.
Listing 14-24. Declaring decision state in Spring Web Flow
1 2 3 4 5 |
<decision-state id="checkLoyaltyPoints"> <if test="…" then="premierCustomer" else="normalCustomer" /> </decision-state> |
- Sub-flow State – allows calling another flow within the parent flow. Listing 14-25 below shows declaring a sub-flow in Spring Web Flow.
Listing 14-25. Declaring sub-flow in Spring Web Flow
1 2 3 4 |
<subflow-state id="testSubflow" subflow="…"> <input name="…" value="…"/> <transition on="…" to="…" /> </subflow-state> |
- End State – designates end of a flow and is declared as show in Listing 14-26 below.
Listing 14-26. Declaring end state in Spring Web Flow
1 |
<end-state id="…" /> |
- Transitions – the path which moves the flow from one state to other. You can also configure transitions which are global in nature as shown in Listing 14-27 below.
Listing 14-27. Declaring global transition in the Spring Web Flow configuration file
1 2 3 |
<global-transitions> <transition on="cancel" to="stopState" /> </global-transitions> |
- Actions – the actual behavior at the various states in a flow.
Page Visitors: 8013
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