A Techno Blog, mainly about Java

Spring Web Flow Beginner – Part Two

As a total beginner to Spring Web Flow, the main thing I have noticed in going through the material is that there is quite a difference between the 1.x and the new release 2.0.

Web Flow | Spring Web Flow Forum

There seems to be in package org.springframework.webflow.action a FlowAction and a FlowExecutor class. As well, the ExternalContext class which is credited to allowing WF to be decoupled from Servlet API .

I do not see a FlowAction or FlowExecutor in org.spring.webflow.action package like in webflow 1.

Instead, lets look at what we have from the example Spring Flow 2.0 Example application.

To use annotations for the transactions within the example, we do the following:

  1. Put an tag tx:annotation-driven in the spring config file
  2. Put @Transactional annotation in the services classes

@Transactional – The @Transactional annotation may be placed before an interface definition, a method on an interface, a class definition, or a public method on a class. However, please note that the mere presence of the @Transactional annotation is not enough to actually turn on the transactional behavior.

You can actually omit the ‘transaction-manager’ attribute in the <tx:annotation-driven/> tag if the bean name of the PlatformTransactionManager that you want to wire in has the name ‘transactionManager’.

<!– Instructs Spring to perfrom declarative transaction managemenet on annotated classes –>

<!– Drives transactions using local JPA APIs –>
<bean id=”transactionManager” class=”org.springframework.orm.jpa.JpaTransactionManager”/>

The LocalContainerEntityManagerFactoryBean can be configured with all Persistent Unit information like is done here.

@PersistenceUnit – annotated on EntityManagerFactory instances are thread-safe

<!– Creates a EntityManagerFactory for use with the Hibernate JPA provider and a simple in-memory data source populated with test data –>
<bean id=”entityManagerFactory” class=”org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean”>
<property name=”jpaVendorAdapter”>
<bean class=”org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter”/>

<!– Deploys a in-memory datasource –>
<bean id=”dataSource” class=”org.springframework.jdbc.datasource.DriverManagerDataSource”>
<property name=”driverClassName” value=”org.hsqldb.jdbcDriver”/>
<property name=”url” value=”jdbc:hsqldb:mem:tutorialSwf”/>
<property name=”username” value=”sa”/>
<property name=”password” value=””/>

<!– Activates annotation-based bean configuration –>

Mapping URLs to Handlers – maps request URLs to handlers. A simple way to create URL mapping rules is to define one as follows:

<!– Maps request URIs to controllers –>
<bean class=”org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”>
<property name=”mappings”>
<prop key=”/f/*”>flowController</prop>
<property name=”defaultHandler”>
<!– Selects view names to render based on the request URI: e.g. /main selects “main” –>
<bean class=”org.springframework.web.servlet.mvc.UrlFilenameViewController”/>

The Flow Handler manages executions of a single flow definition. Above the handler selects view based on the URI in a default handler. To Implement one, extend AbstractFlowHandler.

Flow Controller – The FlowHandler MVC integration approach, you define one handler per flow. This is overkill in the cases where default flow handling rules are sufficient. Web controller for the Spring web MVC framework that routes incoming requests to one or more managed web flows. Requests into the web flow system are managed using a configurable ServletFlowExecutionManager.

<!– Handles requests mapped to the Spring Web Flow system –>
<bean id=”flowController” class=”org.springframework.webflow.mvc.servlet.FlowController“/>

The flow executor is the core Web Flow configuration element. Flow execution listeners are also defined in the flow executor.

<!– Executes flows: the central entry point into the Spring Web Flow system –>
<webflow:flow-executor id=”flowExecutor”>
<webflow:listener ref=”jpaFlowExecutionListener”/>

FlowRegistry – placed where you register your flows

flow-builder-services attribute – customize the services used to build the flows in a registry…When the tag is defined, you only need to reference the services you want to customize.

<!– The registry of executable flow definitions –>
<webflow:flow-registry id=”flowRegistry” flow-builder-services=”facesFlowBuilderServices”>
<webflow:flow-location-pattern value=”/WEB-INF/flows/**/*.xml”/>

flow scoped persistence context – provides isolation of intermediate edits by only committing changes to the database at the end of flow execution. This pattern is often used in conjunction with an optimistic locking strategy to protect the integrity of data modified in parallel by multiple users.

@PersistenceContext – annotated on EntityManager instances are not thread safe

<flow xmlns=”; xmlns:xsi=”;

configure the correct FlowExecutionListener in this case for JPA

<!– Installs a listener that manages JPA persistence contexts for flows that require them –>
<bean id=”jpaFlowExecutionListener” class=”org.springframework.webflow.persistence.JpaFlowExecutionListener”>
<constructor-arg ref=”entityManagerFactory”/>
<constructor-arg ref=”transactionManager”/>

Here is how they handle the view:

<!– Maps logical view names to Facelet templates (e.g. ‘search’ to ‘/WEB-INF/search.xhtml’ –>
<bean id=”faceletsViewResolver” class=”org.springframework.web.servlet.view.UrlBasedViewResolver”>
<property name=”viewClass” value=”org.springframework.faces.mvc.JsfView”/>
<property name=”prefix” value=”/WEB-INF/”/>
<property name=”suffix” value=”.xhtml”/>

Or a simple ViewResolver

July 19, 2008 - Posted by | J2EE


  1. Awesome post, I didn’t thought this was going to be so cool when I read your link.

    Comment by mayowalermels | December 11, 2009 | Reply

  2. […] Exceptions , Testing , Spring 2.0 , IBatis Spring , Web Flow […]

    Pingback by Core Spring via Interface21~SpringSource~VMWare « TechnoBuzz | June 29, 2010 | Reply

  3. A person essentially assist to make severely posts I’d state.
    That is the very first time I frequented your website page and so far?
    I surprised with the analysis you made to create this actual publish amazing.
    Wonderful process!

    Comment by Precio Calzoncillos Calvin Klein | March 29, 2014 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: