DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Revolutionize JSON Parsing in Java With Manifold
  • The Role of Automation in Streamlining DevOps Processes
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Grow Your Skills With Low-Code Automation Tools

Trending

  • Revolutionize JSON Parsing in Java With Manifold
  • The Role of Automation in Streamlining DevOps Processes
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Grow Your Skills With Low-Code Automation Tools
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Webflow: An Example

Spring Webflow: An Example

Roshan Thomas user avatar by
Roshan Thomas
·
Mar. 08, 15 · Interview
Like (1)
Save
Tweet
Share
37.97K Views

Join the DZone community and get the full member experience.

Join For Free

In this article I will give an introduction to Spring Weblow. Using Spring Webflow we can create a guided navigation in the application. Webflow consist of many steps called states. Entering a state typically results in a view being displayed to the user. On that view, user events occur that are handled by the state. These events can trigger transitions to other states which result in view navigations.

Configuring Spring Webflow

Please see below the Spring context file with Webflow configurations.

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:webflow="http://www.springframework.org/schema/webflow-config"    
    
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/webflow-config
        http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
        
        
        <mvc:annotation-driven/>
        
        <!--  Webflow Configuration -->
        <webflow:flow-executor id="flowExecutor"/>
        
        <webflow:flow-registry id="flowRegistry">
            <webflow:flow-location-pattern value="/WEB-INF/*-flow.xml"/>
        </webflow:flow-registry>
        
        <bean id="flowMappings" class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
            <property name="order" value="0"/>
            <property name="flowRegistry" ref="flowRegistry"/>
        </bean>
        
        <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
            <property name="flowExecutor" ref="flowExecutor"/>
        </bean>
       
                            
</beans>

Here for any incoming request, the Spring Webflow registry will be checked to see whether any guided flows are configured. That is why we make the order for Spring Webflow ‘0’.  The flow registry contains all the flows available in the application. If a guided flow is found then the flow executor is initiated.

Next we will see the Spring Webflow file. Each guided flow has a separate file in the application. Here we will see a simple Webflow example. In order to start the flow, you can click on a link which will invoke the correct flow file.

<a href="welcome-flow.do">Start welcome flow</a>

Spring Webflow file

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
                          
                          
        <start-state="welcome">
    
        <view-state id="welcome" view="/welcome.jsp">
            <transition on="continue" to="finish"/>
            <transition on="cancel" to="cancelled"/>
        </view-state>
        
        <end-state id="cancelled" view="/cancelled.jsp"/>
        
        <end-state id="finish" view="/finish.jsp"/>
    

</flow>
        

In this flow file, we set the start state to a state called welcome. Then we defined the view state for the welcome state. In this welcome state we have two different actions. These actions are defined in transition states. Based on the input from the user, request will be navigated to either a ‘cancelled’ state or a ‘finish’ state. Then we defined both the cancelled and finish states. 

I hope this will help you to start with a simple Spring Webflow use case.

Webflow Spring Framework

Opinions expressed by DZone contributors are their own.

Trending

  • Revolutionize JSON Parsing in Java With Manifold
  • The Role of Automation in Streamlining DevOps Processes
  • The Dark Side of DevSecOps and Why We Need Governance Engineering
  • Grow Your Skills With Low-Code Automation Tools

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: