SlideShare a Scribd company logo
1 of 36
Connecting the Views to Work Together
Spring Web Flow
 Spring Web Flow is an extension to Spring MVC that
provides for the development of conversation-style
navigation in a web application.
 The key features provided for by Spring Web Flow are:
 ■ The ability to define an application’s flow external to the
application’s logic.
 ■ The ability to create reusable flows that can be used
across multiple applications.
 Spring Web Flow loosens the coupling between an
application code and its page flow by enabling to define the
flow in a separate, selfcontained flow definition.
Installing Spring Web Flow
 Spring Web Flow, is a subproject of the Spring Framework,
but isn’t part of the Spring Framework, hence is required to
load Spring Web Flow JAR files in application classpath.
 Spring Web Flow can be added in the application using
Maven 2 by setting dependencies in the pom.xml file as
follows:
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-webflow</artifactId>
 <version>1.0.3</version>
 <scope>compile</scope>
 </dependency>
Setting up FlowController
 FlowController is a Spring MVC controller that acts as a front
controller for Spring Web Flow applications.
 FlowController is responsible for handling all requests
pertaining to a flow.
 FlowController is declared in a Spring application context as
follows:
 <bean id="flowController"
 class="org.springframework.webflow.executor.mvc.
 ➥ FlowController">
 <property name="flowExecutor" ref="flowExecutor" />
 </bean>
 The flowExecutor property is the only mandatory property wired
with a flow executor, which ultimately carries out the steps
described in a flow.
Setting up FlowController
 A mapping URL is used to interact with the Spring Web Flow.
 It is configured to the FlowController using handler mappings such as
SimpleUrlHandlerMapping as follows:
 <bean id="urlMapping"
 class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
 <property name="mappings">
 <props>
 <prop key="flow.htm">flowController</prop>
 </props>
 </property>
 </bean>
 SimpleUrlHandlerMapping is most flexible handler mapping as it allows to
map virtually any URL pattern to any controller in the same application.
 ControllerClassNameHandlerMapping can be used if the application is
completely flow-based or if the application’s other controllers are named
appropriately with respect to the URL patterns they’ll be mapped to.
 DispatcherServlet is also configured in the application’s web.xml file as
FlowController is a Spring MVC controller.
Configuring Flow Executor
 The Flow Executor keeps track of all of the flows that are currently being
executed and directs each flow to the state they should go next.
 In Spring 2.0, the flow executor is configured using Spring Web Flow’s
custom configuration schema, by adding Spring Web Flow schema to the
Spring application context’s XML file as follows:
 <beans xmlns= http://www.springframework.org/schema/beans
 xmlns:flow= http://www.springframework.org/schema/webflow-config
 xsi:schemaLocation= "http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
 http://www.springframework.org/schema/webflow-config
 http://www.springframework.org/schema/webflow-config/spring-
webflow-config-1.0.xsd"> ………
 </beans>
 A flow executor is declared using the <flow:executor> element as follows:
 <flow:executor id="flowExecutor“ registry-ref="flowRegistry" />
Under the Hood: Flow Executor
 The <flow:executor> element is used to declare a FlowExecutorFactoryBean in the Spring
application context.
 <bean id="flowExecutor“ class="org.springframework.webflow.config.
 ➥ FlowExecutorFactoryBean">
 <property name="definitionLocator“ ref="flowRegistry"/>
 <property name="executionAttributes">
 <map>
 <entry key="alwaysRedirectOnPause">
 <value type="java.lang.Boolean">true</value>
 </entry>
 </map>
 </property>
 <property name="repositoryType“ value="CONTINUATION"/>
 </bean>
 FlowExecutorFactoryBean uses a flow registry to keep track of all of the flow definition
that it may need.
 The flow registry is given to the flow executor through <flow:executor>’s registry-ref
attribute or through FlowExecutorFactoryBean’s definitionLocator property.
Registering flow definitions
 The flow registry is effectively a librarian that curates a collection
of flow definitions.
 When the flow executor needs a flow, it will ask the flow registry
for it.
 A flow registry can be configured in Spring 2.0 using the
<flow:registry> element, as follows:
 <flow:registry id="flowRegistry">
 <flow:location path="/WEB-INF/flows/**/*-flow.xml" />
 </flow:registry>
 The <flow:registry> element must contain one or more
<flow:location> elements which identifies the path to one or
more flow definitions that the flow registry should manage.
 When a flow definition is loaded into the flow registry, it is
registered with a name that is equal to the filename of the flow
definition after chopping off the file extension (such as “.xml”).
Under the hood: Flow Registry
 The <flow:registry> element is converted to
XmlFlowRegistryFactoryBean <bean> element as follows:
 <bean id="flowRegistry“
class="org.springframework.webflow.engine.
 ➥ builder.xml.XmlFlowRegistryFactoryBean">
 <property name="flowLocations">
 <list>
 <value>/WEB-INF/flows/**/*-flow.xml </value>
 </list>
 </property>
 </bean>
 The XmlFlowRegistryFactoryBean is the class that hides behind
the curtain of the <flow:registry> element.
 The flowLocations property of XmlFlowRegistryFactoryBean
itemizes the flow definitions to be loaded into the registry.
Spring Web Flow Basics: States
 In Spring Web Flow, three main elements make up an
application flow: states, events, and transitions.
 States are points in a flow where some activity takes
place.
 Activities can be the application performing some logic,
or it could be where the user is presented with a page
and asked to take some action.
 The selection of states provided by Spring Web Flow
makes it possible to construct virtually any arrangement
of functionality into a conversational web application.
 View states and Action states represents the user’s
side and the application’s side of conversation
respectively.
Spring Web Flow’s States
State type XML element Purpose
Action <action-state> Action states are where the logic of the flow takes
place. It mostly store, retrieve, derive, process info.
Decision <decision-state> Decision states branch the flow in two or more
directions. Examine info to make routing decision.
End <end-state> The end state is the last stop for a flow. Here the
flow is terminated and user is sent to a final view.
Start <start-state> The start state is the entry point for a flow. It serves
as a reference point to bootstrap a flow.
Subflow <subflow-state> A subflow state starts a new flow within the context
of a flow that is already underway.
View <view-state> A view state pauses the flow and invites the user to
participate in the flow. Used to communicate info.
Basics: Events and Transitions
 Once a state has completed, it fires an event.
 The event is simply a String value that indicates the
outcome of the state.
 The event fired by a state should be mapped to a
transition to serve any purpose.
 Transitions defines the actual flow unlike the state
which defines an activity within a flow.
 A transition indicates which state the flow should go
to next.
Flow Variables
 Flows in Spring Web Flow are defined in XML with all
flow definition files are rooted with the <flow>
element.
 To define flow variables declare a simple domain bean
carrying the necessary information, e.g. Order object.
 The domain object is made available to all of the states
in the flow by declaring it in the flow definition file
with a <var> element as follows:
 <var name="order“
class="com.springinaction.pizza.domain.Order“
scope="flow"/>
Flow Scopes
 Flow variables can be declared to live in one of four
different scopes as below:
Scope Visibility
Request If an object is created in Request scope, it is only visible within
the context of the current request. Request-scoped variables do
not survive redirects.
Flash An object created in Flash scope is visible within the context of
the current request and until the next user event is triggered.
Flash-scoped variables live beyond redirects.
Flow If an object is created in Flow scope, it will be visible within the
context of the current flow execution, but will not be visible to
subflows.
Conversation Objects created in Conversation scope are visible within the
context of the current flow execution as well as in the context of
subflow executions.
Start and End states
 All flows begin with a start state.
 The only thing that occurs within a start state is that a
transition is performed to the next state.
 All flows must have exactly one <start-state> to indicate
where the flow should begin e.g.
 <start-state idref="askForPhoneNumber" />
 The idref attribute indicates the beginning state of the
flow, is the only attribute available to <start-state>.
 The end state is defined as follows:
 <end-state id="finish“ view="orderComplete" />
 An end state terminates the flow and then displays a view
specified by the view attribute.
 The logical view name in end state is mapped to an actual
view implementation using a Spring MVC view resolver.
Start and End states
 The end state could start over with a brand new flow
instead of jumping out of the flow completely.
 <end-state id="finish"
 view="flowRedirect:PizzaOrder-flow" />
 The flowRedirect: directive tells the Spring Web Flow
to redirect the user to the beginning of a flow, e.g. start
of the current flow just finished.
 A flow can have multiple <end-state>s unlike single
<start-state>, in order to define alternate endings for a
flow.
Example Flow1: Pizza Delivery
Web Flow1: Pizza Delivery
 <var name="order“ class="com.springinaction.pizza.domain.Order"
 scope="flow"/>
 <start-state idref="askForPhoneNumber" />
 <view-state id="askForPhoneNumber“ view="phoneNumberForm">
 <transition on="submit" to="lookupCustomer" />
 </view-state>
 <decision-state id="checkDeliveryArea">
 <if test="${flowScope.order.customer.inDeliveryArea}“
 then="showOrder"
 else="warnNoDeliveryAvailable"/>
 </decision-state>
 <view-state id="warnNoDeliveryAvailable“ view="deliveryWarning">
 <transition on="continue" to="showOrder" />
 </view-state>
 <end-state id="finish“ view="flowRedirect:PizzaOrder-flow" />
Web Flow1: Pizza Delivery
 <view-state id="askForPhoneNumber“ view="phoneNumberForm">
 <transition on="submit" to="lookupCustomer" />
 </view-state>
 <action-state id="lookupCustomer">
 <action bean="lookupCustomerAction" />
 <transition on="success“ to="showOrder" />
 <transition on-exception="com.springinaction.pizza.service.
 ➥ CustomerNotFoundException“ to="addNewCustomer" />
 </action-state>
 <view-state id="addNewCustomer" view="newCustomerForm">
 <render-actions> // to create a blank Customer object to bind form data
 <action bean="customerFormAction“ method="setupForm"/>
 </render-actions>
 <transition on="submit" to="showOrder">
 <action bean="customerFormAction" method="bind" />
 <evaluate-action expression=
 "flowScope.order.setCustomer(requestScope.customer)" />
 </transition>
 </view-state>
Example View: phoneNumberForm
 <h2>Customer Lookup</h2>
 <form method="post" action="flow.htm">
 <input type="hidden" name="_flowExecutionKey"
 value="${flowExecutionKey}">
 <b>Phone number: </b>
 <input type="text" name="phoneNumber"/><br/>
 <input type="submit" class="button"
 name="_eventId_submit" value="Submit"/>
 </form>
FlowController
 All links within a Spring Web Flow application goes
through FlowController’s URL mapping.
 The forms are also submitted to FlowController URL by
setting the action parameter to flow.htm which in turn is
mapped to FlowController.
 The FlowController identifies the flow using the
_flowExecutionKey parameter, set to the flow execution
key which is submitted along with the form data.
 The submit button named “_eventId_submit” triggers an
event to Spring Web Flow from a form submission.
 When the form is submitted, the name of the parameter is
split into two parts.
 The first part being _eventId, signals the event identified,
while the second part being submit, is the name of the
event to be triggered when the form is submitted.
Web Flow Action Bean
 The bean referenced by the bean attribute of <action> must implement
Spring Web Flow’s Action interface.
 The execute() is the only mandatory method of the Action interface.
 public class LookupCustomerAction implements Action {
 public Event execute(RequestContext context) throws Exception {
 String phoneNumber =
 context.getRequestParameters().get("phoneNumber");
 Customer customer =
 customerService.lookupCustomer(phoneNumber);
 Order order = (Order) context.getFlowScope().get("order");
 order.setCustomer(customer);
 return new Event(this, "success");
 }
 private CustomerService customerService; // Bean injected
 }
Example View: newCustomerForm
 <%@ taglib prefix="form“
uri="http://www.springframework.org/tags/form" %>
 <h2>New customer</h2>
 <form:form action="flow.htm“ commandName="order.customer">
 <input type="hidden" name="_flowExecutionKey“
 value="${flowExecutionKey}"/>
 <b>Phone: </b> ${requestParameters.phoneNumber} <br/>
 <b>Name: </b> <form:input path="name" /><br/>
 <b>Street address: </b> <form:input path="streetAddress" /><br/>
 <b>City: </b> <form:input path="city" /><br/>
 <b>State: </b> <form:input path="state" /><br/>
 <b>Zip: </b> <form:input path="zipCode" /><br/>
 <input type="submit" class="button“
 name="_eventId_submit" value="Submit"/>
 <input type="submit" class="button"
 name="_eventId_cancel" value="Cancel"/>
 </form:form>
FlowAction
 When the user submits the form, the form data is binds to
a back-end Data object.
 Spring Web Flow provides FlowAction, a special Spring
Web Flow Action implementation that deals with common
form-binding logic.
 The FlowAction is configured as follows:
 <bean id="customerFormAction"
 class="org.springframework.webflow.action.FormAction">
 <property name="formObjectName" value="customer" />
 <property name="formObjectScope" value="REQUEST" />
 <property name="formObjectClass"
 value="com.springinaction.pizza.domain.Customer" />
 </bean>
FlowAction
 FormAction has three important properties that describe the
object that will be bound to the form.
 The formObjectName property specifies the name of the object,
formObjectScope specifies the scope, and formObjectClass
specifies the type.
 The setupForm() method of FormAction creates a blank
Customer object inorder to bind the form data to as follows:
 <render-actions>
 <action bean="customerFormAction“ method="setupForm"/>
 </render-actions>
 Render actions are a way of associating an action with the
rendering of a view.
 FormAction’s setupForm() is similar to the Spring MVC form
controller’s formBackingObject() which prepares an object to be
bound to a form.
Binding during Transition
 <transition on="submit" to="showOrder">
 <action bean="customerFormAction" method="bind" />
 <evaluate-action expression=
 "flowScope.order.setCustomer(requestScope.customer)" />
 </transition>
 The form data is first bind to the form-backing Customer object
and set to the customer property of the flow-scoped Order. This
is a two-step process:
 First, an <action> element is used to ask FormAction’s bind()
method to bind the submitted form data to the form-backing
Customer object that is in request scope.
 Next, with a fully populated Customer object in request scope,
an <evaluate-action> is used to copy the request-scoped
Customer object to the Order object’s customer property.
Example Flow2: Pizza Order
Web Flow2: Pizza Order
 <view-state id="showOrder" view="orderDetails">
 <transition on="addPizza" to="addPizza" />
 <transition on="continue" to="takePayment" />
 </view-state>
 <view-state id="addPizza" view="newPizzaForm">
 <render-actions>
 <action bean="pizzaFormAction" method="setupForm"/>
 </render-actions>
 <transition on="submit" to="showOrder">
 <action bean="pizzaFormAction" method="bind" />
 <evaluate-action expression=
 "flowScope.order.addPizza(requestScope.pizza)" />
 </transition>
 </view-state>
Web Links in Web Flow
 <a href="flow.htm?_flowExecutionKey=${flowExecutionKey}
 ➥ &_eventId=addPizza">Add Pizza</a>
 There are three very important elements of the link’s href attribute that
guide
 Spring Web Flow:
 ■ All the links within a flow must go through the FlowController.
Hence the root of the link is flow.htm, the URL pattern mapped to the
FlowController.
 ■ To identify the flow execution to Spring Web Flow, we’ve set the
_flowExecutionKey parameter to the page-scoped ${flowExecutionKey}
variable. This way FlowController will be able to distinguish one user’s
flow execution from another.
 ■ Finally, the _eventId parameter identifies the event to fire when this
link is clicked on. For example above, we’re firing the addPizza event,
which, as defined in the showOrder state, should trigger a transition to
the addPizza state.
Web Flow3: Pizza Payment
 <view-state id="takePayment" view="paymentForm">
 <transition on="submit" to="submitOrder">
 <bean-action bean="paymentProcessor“ method="approveCreditCard">
 <method-arguments>
 <argument expression= "${requestParameters.creditCardNumber}"/>
 <argument expression= "${requestParameters.expirationMonth}"/>
 <argument expression= "${requestParameters.expirationYear}"/>
 <argument expression= "${flowScope.order.total}" />
 </method-arguments>
 </bean-action>
 </transition>
 <transition on-exception= "com.springinaction.pizza.PaymentException“
 to="takePayment" />
 </view-state>
 <action-state id="submitOrder">
 <bean-action bean="orderService" method="saveOrder">
 <method-arguments>
 <argument expression="${flowScope.order}" />
 </method-arguments>
 </bean-action>
 <transition on="success" to="finish" />
 </action-state>
Action versus Bean-Action
 The downside of using <action> is that the action class
must be an implementation of Spring Web Flow’s
Action interface, without allowing pure POJO action
implementations.
 The <bean-action> provides a nonintrusive alternative,
enabling to invoke any method on any class configured
in the Spring application context, without
implementing a Spring Web Flow–specific interface.
Global Transitions
 The links that fire cancel events within the flow are
handled by allowing the flow to transition to the finish
state in-order to close down the flow execution.
 Spring Web Flow offers the ability to define global
transitions to avoid multiple definitions of redundant
(cancel) transitions occurring throughout the flow.
 Global transitions are transition definitions that are
applicable from any flow state.
 Global transitions can be added to a flow by using <global-
transitions> element as a child of the <flow> element and
place <transition> elements within it as follows:
 <global-transitions>
 <transition on="cancel" to="finish" />
 </global-transitions>
Decision States
 A decision state is the Spring Web Flow equivalent of an if/else
statement in Java.
 It evaluates some Boolean expression and based on the results
will send the flow in one of two directions.
 Decision states are defined with the <decision-state> element as
follows:
 <decision-state id="checkDeliveryArea">
 <if test="${flowScope.order.customer.inDeliveryArea}"
 then="showOrder"
 else="warnNoDeliveryAvailable"/>
 </decision-state>
 The test attribute specifies some expression to be evaluated.
 If the expression evaluates to true, the flow will transition to the
state specified by the then attribute. Otherwise, the flow will
transition to the state given in the else attribute.
Subflows and Substates
 As the flow definitions become lengthy, it is advantageous to extract a
related set of states into their own flow and to reference that flow from
the main flow. E.g. CustomerInfo-flow as below:
 <var name="customer“
 class="com.springinaction.pizza.domain.Customer" scope="flow"/>
 <start-state idref="askForPhoneNumber" />
 <decision-state id="checkDeliveryArea">
 <if test="${flowScope.customer.inDeliveryArea}“ then="finish"
 else="warnNoDeliveryAvailable"/>
 </decision-state>
 ……………………….
 <end-state id="finish">
 <output-mapper>
 <mapping source="flowScope.customer“ target="customer"/>
 </output-mapper>
 </end-state>
Subflows
 A subflow state is a state that references another flow.
 When a flow enters a subflow state, the current flow is suspended and the referenced
flow is executed, analogous to method calls in Java.
 <subflow-state id="getCustomerInfo" flow="CustomerInfo-flow" >
 <attribute-mapper>
 <output-mapper>
 <mapping source="customer" target="flowScope.order.customer"/>
 </output-mapper>
 </attribute-mapper>
 <transition on="finish" to="showOrder" />
 </subflow-state>
 In above example, the getCustomerInfo state is a subflow state that references the flow
named CustomerInfo-flow.
 In the CustomerInfo-flow, the flow-scoped Customer object is mapped to an output
variable named customer, while in the <subflow-state> that output variable is mapped to
the customer property of the order flow’s flow-scoped Order object.
 Further, the <start-state> which referred to the askForPhoneNumber state, refers to the
getCustomerInfo state of CustomerInfo-flow were askForPhoneNumber is the start state:
 <start-state idref="getCustomerInfo" />
Integrating with Jakarta Struts
 Spring Web Flow integrates into Struts through FlowAction, a Struts
Action implementation similar to FlowController in Spring MVC.
 FlowAction is a Struts-specific front controller for Spring Web Flow.
 It is configured in <action-mappings> section of strutsconfig.xml using
<action> tag as below:
 <action path="/flow“ name="actionForm“ scope="request"
 type="org.springframework.webflow.executor.struts.FlowAction"/>
 FlowAction uses parameters to guide the flow which are bound to
SpringBindingActionForm, an ActionForm implementation configured
as follows:
 <form-bean name="actionForm" type= "org.springframework.web.struts.
 ➥ SpringBindingActionForm"/>
 The name of the <form-bean> is the same as the name of the <action> to
allow Struts to know the SpringBindingActionForm to be used to bind
parameters for FlowAction.
 In a Struts-based flow a <view-state>’s view refers to a Struts <forward>.

More Related Content

What's hot

Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSCarol McDonald
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVCGuy Nir
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component BehaviorsAndy Schwartz
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Michał Orman
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Arun Gupta
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsBG Java EE Course
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WSIndicThreads
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Fahad Golra
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2Jim Driscoll
 
JSF basics
JSF basicsJSF basics
JSF basicsairbo
 
Java Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkJava Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkGuo Albert
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & AjaxAng Chen
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoasZeid Hassan
 

What's hot (20)

Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WS
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
JSF basics
JSF basicsJSF basics
JSF basics
 
Vue, vue router, vuex
Vue, vue router, vuexVue, vue router, vuex
Vue, vue router, vuex
 
Java Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkJava Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC Framework
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
Jsp & Ajax
Jsp & AjaxJsp & Ajax
Jsp & Ajax
 
Rest web service_with_spring_hateoas
Rest web service_with_spring_hateoasRest web service_with_spring_hateoas
Rest web service_with_spring_hateoas
 

Viewers also liked

Viewers also liked (11)

Spring webflow-reference
Spring webflow-referenceSpring webflow-reference
Spring webflow-reference
 
Ajax en Java - GTI780 & MTI780 - ETS - A09
Ajax en Java - GTI780 & MTI780 - ETS - A09Ajax en Java - GTI780 & MTI780 - ETS - A09
Ajax en Java - GTI780 & MTI780 - ETS - A09
 
Presentation Spring, Spring MVC
Presentation Spring, Spring MVCPresentation Spring, Spring MVC
Presentation Spring, Spring MVC
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
 
Presentation Spring
Presentation SpringPresentation Spring
Presentation Spring
 
Rapport d'activité 2012
Rapport d'activité 2012Rapport d'activité 2012
Rapport d'activité 2012
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
Ajax intro 2pp
Ajax intro 2ppAjax intro 2pp
Ajax intro 2pp
 
Framework Orienté objet
Framework Orienté objetFramework Orienté objet
Framework Orienté objet
 

Similar to Spring Web Webflow

Similar to Spring Web Webflow (20)

Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Sprint Portlet MVC Seminar
Sprint Portlet MVC SeminarSprint Portlet MVC Seminar
Sprint Portlet MVC Seminar
 
Corespring
CorespringCorespring
Corespring
 
Corespring
CorespringCorespring
Corespring
 
Sap Tech Ed06 Asug Wf
Sap Tech Ed06 Asug WfSap Tech Ed06 Asug Wf
Sap Tech Ed06 Asug Wf
 
Intro to flask2
Intro to flask2Intro to flask2
Intro to flask2
 
Intro to flask
Intro to flaskIntro to flask
Intro to flask
 
Spring tutorial
Spring tutorialSpring tutorial
Spring tutorial
 
Wwf
WwfWwf
Wwf
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Silicon Valley Code Camp - JSF Controller for Reusability
Silicon Valley Code Camp - JSF Controller for ReusabilitySilicon Valley Code Camp - JSF Controller for Reusability
Silicon Valley Code Camp - JSF Controller for Reusability
 
Spring Web Flow
Spring Web FlowSpring Web Flow
Spring Web Flow
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
 
SCDJWS 5. JAX-WS
SCDJWS 5. JAX-WSSCDJWS 5. JAX-WS
SCDJWS 5. JAX-WS
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Windows Workflow Foundation
Windows Workflow FoundationWindows Workflow Foundation
Windows Workflow Foundation
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
MVC
MVCMVC
MVC
 
Ds
DsDs
Ds
 

More from Emprovise

Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Emprovise
 
Leadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessLeadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessEmprovise
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layerEmprovise
 
Effective java
Effective javaEffective java
Effective javaEmprovise
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance FeaturesEmprovise
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
RESTful WebServices
RESTful WebServicesRESTful WebServices
RESTful WebServicesEmprovise
 
J2EE Patterns
J2EE PatternsJ2EE Patterns
J2EE PatternsEmprovise
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web ViewsEmprovise
 
Enterprise Spring
Enterprise SpringEnterprise Spring
Enterprise SpringEmprovise
 
Spring Basics
Spring BasicsSpring Basics
Spring BasicsEmprovise
 
Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 AdvanceEmprovise
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 FrameworkEmprovise
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance ConceptsEmprovise
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesEmprovise
 

More from Emprovise (20)

Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
 
Leadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessLeadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/Business
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layer
 
Effective java
Effective javaEffective java
Effective java
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
RESTful WebServices
RESTful WebServicesRESTful WebServices
RESTful WebServices
 
J2EE Patterns
J2EE PatternsJ2EE Patterns
J2EE Patterns
 
Spring JMS
Spring JMSSpring JMS
Spring JMS
 
JMS
JMSJMS
JMS
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web Views
 
Enterprise Spring
Enterprise SpringEnterprise Spring
Enterprise Spring
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 Advance
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance Concepts
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 

Spring Web Webflow

  • 1. Connecting the Views to Work Together
  • 2. Spring Web Flow  Spring Web Flow is an extension to Spring MVC that provides for the development of conversation-style navigation in a web application.  The key features provided for by Spring Web Flow are:  ■ The ability to define an application’s flow external to the application’s logic.  ■ The ability to create reusable flows that can be used across multiple applications.  Spring Web Flow loosens the coupling between an application code and its page flow by enabling to define the flow in a separate, selfcontained flow definition.
  • 3. Installing Spring Web Flow  Spring Web Flow, is a subproject of the Spring Framework, but isn’t part of the Spring Framework, hence is required to load Spring Web Flow JAR files in application classpath.  Spring Web Flow can be added in the application using Maven 2 by setting dependencies in the pom.xml file as follows:  <dependency>  <groupId>org.springframework</groupId>  <artifactId>spring-webflow</artifactId>  <version>1.0.3</version>  <scope>compile</scope>  </dependency>
  • 4. Setting up FlowController  FlowController is a Spring MVC controller that acts as a front controller for Spring Web Flow applications.  FlowController is responsible for handling all requests pertaining to a flow.  FlowController is declared in a Spring application context as follows:  <bean id="flowController"  class="org.springframework.webflow.executor.mvc.  ➥ FlowController">  <property name="flowExecutor" ref="flowExecutor" />  </bean>  The flowExecutor property is the only mandatory property wired with a flow executor, which ultimately carries out the steps described in a flow.
  • 5. Setting up FlowController  A mapping URL is used to interact with the Spring Web Flow.  It is configured to the FlowController using handler mappings such as SimpleUrlHandlerMapping as follows:  <bean id="urlMapping"  class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">  <property name="mappings">  <props>  <prop key="flow.htm">flowController</prop>  </props>  </property>  </bean>  SimpleUrlHandlerMapping is most flexible handler mapping as it allows to map virtually any URL pattern to any controller in the same application.  ControllerClassNameHandlerMapping can be used if the application is completely flow-based or if the application’s other controllers are named appropriately with respect to the URL patterns they’ll be mapped to.  DispatcherServlet is also configured in the application’s web.xml file as FlowController is a Spring MVC controller.
  • 6. Configuring Flow Executor  The Flow Executor keeps track of all of the flows that are currently being executed and directs each flow to the state they should go next.  In Spring 2.0, the flow executor is configured using Spring Web Flow’s custom configuration schema, by adding Spring Web Flow schema to the Spring application context’s XML file as follows:  <beans xmlns= http://www.springframework.org/schema/beans  xmlns:flow= http://www.springframework.org/schema/webflow-config  xsi:schemaLocation= "http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd  http://www.springframework.org/schema/webflow-config  http://www.springframework.org/schema/webflow-config/spring- webflow-config-1.0.xsd"> ………  </beans>  A flow executor is declared using the <flow:executor> element as follows:  <flow:executor id="flowExecutor“ registry-ref="flowRegistry" />
  • 7. Under the Hood: Flow Executor  The <flow:executor> element is used to declare a FlowExecutorFactoryBean in the Spring application context.  <bean id="flowExecutor“ class="org.springframework.webflow.config.  ➥ FlowExecutorFactoryBean">  <property name="definitionLocator“ ref="flowRegistry"/>  <property name="executionAttributes">  <map>  <entry key="alwaysRedirectOnPause">  <value type="java.lang.Boolean">true</value>  </entry>  </map>  </property>  <property name="repositoryType“ value="CONTINUATION"/>  </bean>  FlowExecutorFactoryBean uses a flow registry to keep track of all of the flow definition that it may need.  The flow registry is given to the flow executor through <flow:executor>’s registry-ref attribute or through FlowExecutorFactoryBean’s definitionLocator property.
  • 8. Registering flow definitions  The flow registry is effectively a librarian that curates a collection of flow definitions.  When the flow executor needs a flow, it will ask the flow registry for it.  A flow registry can be configured in Spring 2.0 using the <flow:registry> element, as follows:  <flow:registry id="flowRegistry">  <flow:location path="/WEB-INF/flows/**/*-flow.xml" />  </flow:registry>  The <flow:registry> element must contain one or more <flow:location> elements which identifies the path to one or more flow definitions that the flow registry should manage.  When a flow definition is loaded into the flow registry, it is registered with a name that is equal to the filename of the flow definition after chopping off the file extension (such as “.xml”).
  • 9. Under the hood: Flow Registry  The <flow:registry> element is converted to XmlFlowRegistryFactoryBean <bean> element as follows:  <bean id="flowRegistry“ class="org.springframework.webflow.engine.  ➥ builder.xml.XmlFlowRegistryFactoryBean">  <property name="flowLocations">  <list>  <value>/WEB-INF/flows/**/*-flow.xml </value>  </list>  </property>  </bean>  The XmlFlowRegistryFactoryBean is the class that hides behind the curtain of the <flow:registry> element.  The flowLocations property of XmlFlowRegistryFactoryBean itemizes the flow definitions to be loaded into the registry.
  • 10. Spring Web Flow Basics: States  In Spring Web Flow, three main elements make up an application flow: states, events, and transitions.  States are points in a flow where some activity takes place.  Activities can be the application performing some logic, or it could be where the user is presented with a page and asked to take some action.  The selection of states provided by Spring Web Flow makes it possible to construct virtually any arrangement of functionality into a conversational web application.  View states and Action states represents the user’s side and the application’s side of conversation respectively.
  • 11. Spring Web Flow’s States State type XML element Purpose Action <action-state> Action states are where the logic of the flow takes place. It mostly store, retrieve, derive, process info. Decision <decision-state> Decision states branch the flow in two or more directions. Examine info to make routing decision. End <end-state> The end state is the last stop for a flow. Here the flow is terminated and user is sent to a final view. Start <start-state> The start state is the entry point for a flow. It serves as a reference point to bootstrap a flow. Subflow <subflow-state> A subflow state starts a new flow within the context of a flow that is already underway. View <view-state> A view state pauses the flow and invites the user to participate in the flow. Used to communicate info.
  • 12. Basics: Events and Transitions  Once a state has completed, it fires an event.  The event is simply a String value that indicates the outcome of the state.  The event fired by a state should be mapped to a transition to serve any purpose.  Transitions defines the actual flow unlike the state which defines an activity within a flow.  A transition indicates which state the flow should go to next.
  • 13. Flow Variables  Flows in Spring Web Flow are defined in XML with all flow definition files are rooted with the <flow> element.  To define flow variables declare a simple domain bean carrying the necessary information, e.g. Order object.  The domain object is made available to all of the states in the flow by declaring it in the flow definition file with a <var> element as follows:  <var name="order“ class="com.springinaction.pizza.domain.Order“ scope="flow"/>
  • 14. Flow Scopes  Flow variables can be declared to live in one of four different scopes as below: Scope Visibility Request If an object is created in Request scope, it is only visible within the context of the current request. Request-scoped variables do not survive redirects. Flash An object created in Flash scope is visible within the context of the current request and until the next user event is triggered. Flash-scoped variables live beyond redirects. Flow If an object is created in Flow scope, it will be visible within the context of the current flow execution, but will not be visible to subflows. Conversation Objects created in Conversation scope are visible within the context of the current flow execution as well as in the context of subflow executions.
  • 15. Start and End states  All flows begin with a start state.  The only thing that occurs within a start state is that a transition is performed to the next state.  All flows must have exactly one <start-state> to indicate where the flow should begin e.g.  <start-state idref="askForPhoneNumber" />  The idref attribute indicates the beginning state of the flow, is the only attribute available to <start-state>.  The end state is defined as follows:  <end-state id="finish“ view="orderComplete" />  An end state terminates the flow and then displays a view specified by the view attribute.  The logical view name in end state is mapped to an actual view implementation using a Spring MVC view resolver.
  • 16. Start and End states  The end state could start over with a brand new flow instead of jumping out of the flow completely.  <end-state id="finish"  view="flowRedirect:PizzaOrder-flow" />  The flowRedirect: directive tells the Spring Web Flow to redirect the user to the beginning of a flow, e.g. start of the current flow just finished.  A flow can have multiple <end-state>s unlike single <start-state>, in order to define alternate endings for a flow.
  • 18. Web Flow1: Pizza Delivery  <var name="order“ class="com.springinaction.pizza.domain.Order"  scope="flow"/>  <start-state idref="askForPhoneNumber" />  <view-state id="askForPhoneNumber“ view="phoneNumberForm">  <transition on="submit" to="lookupCustomer" />  </view-state>  <decision-state id="checkDeliveryArea">  <if test="${flowScope.order.customer.inDeliveryArea}“  then="showOrder"  else="warnNoDeliveryAvailable"/>  </decision-state>  <view-state id="warnNoDeliveryAvailable“ view="deliveryWarning">  <transition on="continue" to="showOrder" />  </view-state>  <end-state id="finish“ view="flowRedirect:PizzaOrder-flow" />
  • 19. Web Flow1: Pizza Delivery  <view-state id="askForPhoneNumber“ view="phoneNumberForm">  <transition on="submit" to="lookupCustomer" />  </view-state>  <action-state id="lookupCustomer">  <action bean="lookupCustomerAction" />  <transition on="success“ to="showOrder" />  <transition on-exception="com.springinaction.pizza.service.  ➥ CustomerNotFoundException“ to="addNewCustomer" />  </action-state>  <view-state id="addNewCustomer" view="newCustomerForm">  <render-actions> // to create a blank Customer object to bind form data  <action bean="customerFormAction“ method="setupForm"/>  </render-actions>  <transition on="submit" to="showOrder">  <action bean="customerFormAction" method="bind" />  <evaluate-action expression=  "flowScope.order.setCustomer(requestScope.customer)" />  </transition>  </view-state>
  • 20. Example View: phoneNumberForm  <h2>Customer Lookup</h2>  <form method="post" action="flow.htm">  <input type="hidden" name="_flowExecutionKey"  value="${flowExecutionKey}">  <b>Phone number: </b>  <input type="text" name="phoneNumber"/><br/>  <input type="submit" class="button"  name="_eventId_submit" value="Submit"/>  </form>
  • 21. FlowController  All links within a Spring Web Flow application goes through FlowController’s URL mapping.  The forms are also submitted to FlowController URL by setting the action parameter to flow.htm which in turn is mapped to FlowController.  The FlowController identifies the flow using the _flowExecutionKey parameter, set to the flow execution key which is submitted along with the form data.  The submit button named “_eventId_submit” triggers an event to Spring Web Flow from a form submission.  When the form is submitted, the name of the parameter is split into two parts.  The first part being _eventId, signals the event identified, while the second part being submit, is the name of the event to be triggered when the form is submitted.
  • 22. Web Flow Action Bean  The bean referenced by the bean attribute of <action> must implement Spring Web Flow’s Action interface.  The execute() is the only mandatory method of the Action interface.  public class LookupCustomerAction implements Action {  public Event execute(RequestContext context) throws Exception {  String phoneNumber =  context.getRequestParameters().get("phoneNumber");  Customer customer =  customerService.lookupCustomer(phoneNumber);  Order order = (Order) context.getFlowScope().get("order");  order.setCustomer(customer);  return new Event(this, "success");  }  private CustomerService customerService; // Bean injected  }
  • 23. Example View: newCustomerForm  <%@ taglib prefix="form“ uri="http://www.springframework.org/tags/form" %>  <h2>New customer</h2>  <form:form action="flow.htm“ commandName="order.customer">  <input type="hidden" name="_flowExecutionKey“  value="${flowExecutionKey}"/>  <b>Phone: </b> ${requestParameters.phoneNumber} <br/>  <b>Name: </b> <form:input path="name" /><br/>  <b>Street address: </b> <form:input path="streetAddress" /><br/>  <b>City: </b> <form:input path="city" /><br/>  <b>State: </b> <form:input path="state" /><br/>  <b>Zip: </b> <form:input path="zipCode" /><br/>  <input type="submit" class="button“  name="_eventId_submit" value="Submit"/>  <input type="submit" class="button"  name="_eventId_cancel" value="Cancel"/>  </form:form>
  • 24. FlowAction  When the user submits the form, the form data is binds to a back-end Data object.  Spring Web Flow provides FlowAction, a special Spring Web Flow Action implementation that deals with common form-binding logic.  The FlowAction is configured as follows:  <bean id="customerFormAction"  class="org.springframework.webflow.action.FormAction">  <property name="formObjectName" value="customer" />  <property name="formObjectScope" value="REQUEST" />  <property name="formObjectClass"  value="com.springinaction.pizza.domain.Customer" />  </bean>
  • 25. FlowAction  FormAction has three important properties that describe the object that will be bound to the form.  The formObjectName property specifies the name of the object, formObjectScope specifies the scope, and formObjectClass specifies the type.  The setupForm() method of FormAction creates a blank Customer object inorder to bind the form data to as follows:  <render-actions>  <action bean="customerFormAction“ method="setupForm"/>  </render-actions>  Render actions are a way of associating an action with the rendering of a view.  FormAction’s setupForm() is similar to the Spring MVC form controller’s formBackingObject() which prepares an object to be bound to a form.
  • 26. Binding during Transition  <transition on="submit" to="showOrder">  <action bean="customerFormAction" method="bind" />  <evaluate-action expression=  "flowScope.order.setCustomer(requestScope.customer)" />  </transition>  The form data is first bind to the form-backing Customer object and set to the customer property of the flow-scoped Order. This is a two-step process:  First, an <action> element is used to ask FormAction’s bind() method to bind the submitted form data to the form-backing Customer object that is in request scope.  Next, with a fully populated Customer object in request scope, an <evaluate-action> is used to copy the request-scoped Customer object to the Order object’s customer property.
  • 28. Web Flow2: Pizza Order  <view-state id="showOrder" view="orderDetails">  <transition on="addPizza" to="addPizza" />  <transition on="continue" to="takePayment" />  </view-state>  <view-state id="addPizza" view="newPizzaForm">  <render-actions>  <action bean="pizzaFormAction" method="setupForm"/>  </render-actions>  <transition on="submit" to="showOrder">  <action bean="pizzaFormAction" method="bind" />  <evaluate-action expression=  "flowScope.order.addPizza(requestScope.pizza)" />  </transition>  </view-state>
  • 29. Web Links in Web Flow  <a href="flow.htm?_flowExecutionKey=${flowExecutionKey}  ➥ &_eventId=addPizza">Add Pizza</a>  There are three very important elements of the link’s href attribute that guide  Spring Web Flow:  ■ All the links within a flow must go through the FlowController. Hence the root of the link is flow.htm, the URL pattern mapped to the FlowController.  ■ To identify the flow execution to Spring Web Flow, we’ve set the _flowExecutionKey parameter to the page-scoped ${flowExecutionKey} variable. This way FlowController will be able to distinguish one user’s flow execution from another.  ■ Finally, the _eventId parameter identifies the event to fire when this link is clicked on. For example above, we’re firing the addPizza event, which, as defined in the showOrder state, should trigger a transition to the addPizza state.
  • 30. Web Flow3: Pizza Payment  <view-state id="takePayment" view="paymentForm">  <transition on="submit" to="submitOrder">  <bean-action bean="paymentProcessor“ method="approveCreditCard">  <method-arguments>  <argument expression= "${requestParameters.creditCardNumber}"/>  <argument expression= "${requestParameters.expirationMonth}"/>  <argument expression= "${requestParameters.expirationYear}"/>  <argument expression= "${flowScope.order.total}" />  </method-arguments>  </bean-action>  </transition>  <transition on-exception= "com.springinaction.pizza.PaymentException“  to="takePayment" />  </view-state>  <action-state id="submitOrder">  <bean-action bean="orderService" method="saveOrder">  <method-arguments>  <argument expression="${flowScope.order}" />  </method-arguments>  </bean-action>  <transition on="success" to="finish" />  </action-state>
  • 31. Action versus Bean-Action  The downside of using <action> is that the action class must be an implementation of Spring Web Flow’s Action interface, without allowing pure POJO action implementations.  The <bean-action> provides a nonintrusive alternative, enabling to invoke any method on any class configured in the Spring application context, without implementing a Spring Web Flow–specific interface.
  • 32. Global Transitions  The links that fire cancel events within the flow are handled by allowing the flow to transition to the finish state in-order to close down the flow execution.  Spring Web Flow offers the ability to define global transitions to avoid multiple definitions of redundant (cancel) transitions occurring throughout the flow.  Global transitions are transition definitions that are applicable from any flow state.  Global transitions can be added to a flow by using <global- transitions> element as a child of the <flow> element and place <transition> elements within it as follows:  <global-transitions>  <transition on="cancel" to="finish" />  </global-transitions>
  • 33. Decision States  A decision state is the Spring Web Flow equivalent of an if/else statement in Java.  It evaluates some Boolean expression and based on the results will send the flow in one of two directions.  Decision states are defined with the <decision-state> element as follows:  <decision-state id="checkDeliveryArea">  <if test="${flowScope.order.customer.inDeliveryArea}"  then="showOrder"  else="warnNoDeliveryAvailable"/>  </decision-state>  The test attribute specifies some expression to be evaluated.  If the expression evaluates to true, the flow will transition to the state specified by the then attribute. Otherwise, the flow will transition to the state given in the else attribute.
  • 34. Subflows and Substates  As the flow definitions become lengthy, it is advantageous to extract a related set of states into their own flow and to reference that flow from the main flow. E.g. CustomerInfo-flow as below:  <var name="customer“  class="com.springinaction.pizza.domain.Customer" scope="flow"/>  <start-state idref="askForPhoneNumber" />  <decision-state id="checkDeliveryArea">  <if test="${flowScope.customer.inDeliveryArea}“ then="finish"  else="warnNoDeliveryAvailable"/>  </decision-state>  ……………………….  <end-state id="finish">  <output-mapper>  <mapping source="flowScope.customer“ target="customer"/>  </output-mapper>  </end-state>
  • 35. Subflows  A subflow state is a state that references another flow.  When a flow enters a subflow state, the current flow is suspended and the referenced flow is executed, analogous to method calls in Java.  <subflow-state id="getCustomerInfo" flow="CustomerInfo-flow" >  <attribute-mapper>  <output-mapper>  <mapping source="customer" target="flowScope.order.customer"/>  </output-mapper>  </attribute-mapper>  <transition on="finish" to="showOrder" />  </subflow-state>  In above example, the getCustomerInfo state is a subflow state that references the flow named CustomerInfo-flow.  In the CustomerInfo-flow, the flow-scoped Customer object is mapped to an output variable named customer, while in the <subflow-state> that output variable is mapped to the customer property of the order flow’s flow-scoped Order object.  Further, the <start-state> which referred to the askForPhoneNumber state, refers to the getCustomerInfo state of CustomerInfo-flow were askForPhoneNumber is the start state:  <start-state idref="getCustomerInfo" />
  • 36. Integrating with Jakarta Struts  Spring Web Flow integrates into Struts through FlowAction, a Struts Action implementation similar to FlowController in Spring MVC.  FlowAction is a Struts-specific front controller for Spring Web Flow.  It is configured in <action-mappings> section of strutsconfig.xml using <action> tag as below:  <action path="/flow“ name="actionForm“ scope="request"  type="org.springframework.webflow.executor.struts.FlowAction"/>  FlowAction uses parameters to guide the flow which are bound to SpringBindingActionForm, an ActionForm implementation configured as follows:  <form-bean name="actionForm" type= "org.springframework.web.struts.  ➥ SpringBindingActionForm"/>  The name of the <form-bean> is the same as the name of the <action> to allow Struts to know the SpringBindingActionForm to be used to bind parameters for FlowAction.  In a Struts-based flow a <view-state>’s view refers to a Struts <forward>.