Spring Web Flow 2 Web Development - Stauble Markus - E-Book

Spring Web Flow 2 Web Development E-Book

Stauble Markus

0,0
20,53 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

In Detail

Many web applications need to take the user through a defined series of steps such as e-commerce checkouts or user registrations. Spring Web Flow works well for rich and flexible user interaction, additionally it helps you to describe the flow of websites in complex processes. Spring Web Flow 2 provides the perfect way to build these kinds of features, keeping them secure, reliable, and easy to maintain.

This book provides a platform on which you can build your own applications and services. It gives detailed information on Spring basics and covers core topics involving testing, security, and so on. We develop a complete, robust web application using the latest version of Spring, where page navigation is done on-the-fly.

This book teaches you how to work with Spring Web Flow. It covers both basic and advanced aspects and provides a detailed reference of the features Spring Web Flow. The book helps readers to extend the framework.

The integration of Spring and Java Server Pages is clearly explained in the book. The book also explains the essential modules of the complete Spring framework stack and teaches how to manage the control flow of a Spring web application.

The Spring Faces module will provide integration between Spring Web Flow and Java Server Faces (JSF). Testing, an important aspect of the software development process is covered towards the end; the question of how to test a Spring Web Flow application is answered.

A practical guide to designing powerful web applications with the Spring Web Flow framework

Approach

This book is a tutorial, with plenty of step-by-step instructions beginning with "getting started" material, followed by advanced coverage of this technology. The book has a practical approach towards the Spring MVC framework and is packed with practical examples and code.

Who this book is for

This book is targeted at Java web application developers who want to work on Spring Web Flow. This book is a must-read for those who desire to bridge the gap between the popular web framework and the popular application framework. It requires prior knowledge of the Spring framework, but no prior knowledge of Spring Web Flow.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 261

Veröffentlichungsjahr: 2009

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Spring Web Flow 2 Web Development
Credits
About the Authors
About the Reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code for the book
Errata
Piracy
Questions
1. Introduction
Three cornerstones: Spring, Spring MVC, and Spring Web Flow
Spring Framework
Spring MVC
Spring Web Flow
What is Spring Web Flow
The elements of Spring Web Flow: flow, view, and conversation
Flow
View
Conversation
The Spring Web Flow elements: an example
The new major release: Spring Web Flow 2.0
Spring Web Flow
Spring Faces
Spring JavaScript
Spring Binding
Introduction to a new version
Automatic model binding
Support for a new expression language
Flash scope is now a real flash scope
Spring Faces
Flow managed persistence
External redirects
Summary
2. Setup for Spring Web Flow 2
Installation of Spring Web Flow 2
Inside the distribution
The examples inside the distribution
Building the examples from the source code
Installing the examples on your local machine
Support for developers
Build systems
Ant
Maven
IDE
Eclipse and Spring IDE
NetBeans
A sample for a quick start
Overview over the example
The basics
Building the service and database layer
The web.xml file
Dependencies
Summary
3. The Basics of Spring Web Flow 2
Elements of a flow
The entry point to the flow
Section head
Section data
The metadata of a flow
Persistence context
FlowScoped Persistence Context
Direct usage of persistence-context
Usage of the persistence-context attribute
Section input
Programming in a flow
The scopes
Resolving variables
The flow instance variables
Assign a value to a scope variable
Access the value of a scope
Inputs
The states
The start-state
The action-state and execution of business logic
Details of a transition
The view-state
Validation inside the view-state
More details about validation
The decision-state
The subflow-state
The end-state
The exit point
Section footer
global-transitions: global handling of events
on-end: execution of actions at the end of the flow
output: output of the flow
exception-handler: exceptions between the execution of a flow
bean-import: declaring beans for a flow
Internals of building a flow
Configuration
FlowRegistry
FlowExecutor
FlowExecutor Listeners
Internals of the Webflow Configuration
Inheritance inside a flow definition
Inheritance for flows
Inheritance for states
Merge or no merge
The complete flow for the example
Summary
4. Spring Faces
Enabling Spring Faces support
Inside the Facelets technology
The ResourceServlet
Internals of the ResourceServlet
Configuration of the application context
Using Spring Faces
Overview of all tags of the Spring Faces tag library
A complete example
Creating the input page
The Header part
The Name part
The Description part
The Fix until part
The Buttons part
Handling of errors
Reflecting the actions of the buttons into the flow definition file
Showing the results
Integration with other JavaServer Faces component libraries
Integration with JBoss RichFaces
Integration with Apache MyFaces Trinidad
Summary
5. Mastering Spring Web Flow
Subflows
Spring JavaScript
What is AJAX?
Installing Spring JavaScript
The first example with Spring JavaScript
Apache Tiles integration
Tiles and AJAX
The Web Flow configuration
flow
attribute
secured
persistence-context
var
input
output
actionTypes
evaluate
render
set
on-start
on-end
transition
global-transitions
exception-handler
bean-import
action-state
view-state
decision-state
subflow-state
end-state
Summary
6. Testing Spring Web Flow Applications
How to test a Spring Web Flow application
The first example
A look into the source code
First steps in testing
Testing Persistent Contexts
A short introduction to EasyMock
Testing subflows
More testing with EasyMock
Summary
7. Security
Introducing Spring Security
Installing Spring Security
Basic authentication with Spring Security
Setting up your web.xml
Advanced Spring Security configuration
UserDetails
Using database access to retrieve users
Securing parts of a web page
Securing method invocations
Using Spring Security with Spring Web Flow
Changing the user's password
Summary
A. flow.trac:The Model for the Examples
flow.trac
Item
User
Role
Project
Issue
Type
Priority
Comment
Attachment
Summary
B. Running on the SpringSource dm Server
Introduction to the SpringSource dm Server
Installation of the SpringSource dm Server
Migrating an application
Summary
Index

Spring Web Flow 2 Web Development

Markus Stäuble

Sven Lüppken

Spring Web Flow 2 Web Development

Copyright © 2009 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: March 2009

Production Reference: 1120309

Published by Packt Publishing Ltd.

32 Lincoln Road

Olton

Birmingham, B27 6PA, UK.

ISBN 978-1-847195-42-5

www.packtpub.com

Cover Image by Vinayak Chittar (<[email protected]>)

Credits

Authors

Sven Lüppken

Markus Stäuble

Reviewers

Luca Masini

Xinyu Liu

Senior Acquisition Editor

David Barnes

Development Editor

Shilpa Dube

Technical Editors

Dhiraj Bellani

Reshma Sundaresan

Copy Editor

Sumathi Sridhar

Indexer

Rekha Nair

Production Editorial Manager

Abhijeet Deobhakta

Project Team Leader

Lata Basantani

Project Coordinator

Leena Purkait

Proofreader

Laura Booth

Production Coordinator

Aparna Bhagat

Cover Work

Aparna Bhagat

About the Authors

Sven Lüppken holds a degree in Computer Science, which he passed with distinction. He is currently employed as a Java Software Developer at CBC Cologne Broadcasting Center GmbH, one of the leading broadcasting and production companies in Germany and a part of Media Group RTL Germany. Sven started programming in C and C++ at the age of sixteen and quickly fell in love with the Java programming language during his studies. When he got the chance to write his diploma thesis about object-relational mapping technologies, he accepted at once. Since then, he has integrated Hibernate and the JPA in many projects, always in conjunction with the Spring Framework.

I would like to dedicate my first book to my fiancée Frauke. Thank you for having always been supportive and understanding when I was spending my evenings and weekends writing this book. I would also like to thank Markus for giving me the opportunity to write this book, I'm very grateful to him. Some of my friends provided me with invaluable feedback, ideas, and criticism: Dr. Thomas Richert, Alexandre Morozov, and Oliver Fehrentz. Thanks guys!

Special thanks to my parents, who have supported and encouraged me my entire life. Thank you so much!

Markus Stäuble is currently working as a CTO at namics (Deutschland) GmbH. He has a Master's degree in Computer Science. He started programming with Java in the year 1999. After that, he has earned much experience in building Java enterprise systems, especially web applications. He has a deep knowledge of the Java platform and the tools and frameworks around Java.

There are many people who supported the writing of this book. But there is especially one person whom I want to say thank you, my wife Maria Elena. She greatly supported the writing and gave me the power and energy to finish this book.

About the Reviewers

Luca Masini was born in Florence in 1971. He is a senior software engineer and architect. He has been heavily involved from his first days in the Java world as a consultant for the major Italian banks, developing integration software and as a technical leader in many of the flagship projects. He worked for the adoption of Sun's J2EE standards in environments where COBOL was the leading language, and then he shifted his eyes toward open source, in particular IoC containers, ORM tools, and UI frameworks. As such, he adopted early products like Spring, Hibernate, and Struts, giving customers a technological advantage. Now he is working in enterprise ICT to simplify application development, thanks to Java EE 5, simplified standard, build tools, and project archetypes.

He also worked in the review of Google Web Toolkit GWT Java AJAX Programming, by Packt Publishing.

I would like to thank my son Niccolò.

Xinyu Liu had his graduate educations at the George Washington University. As a Sun Microsystems certified enterprise architect and developer, he has intensive application design and development experience across JavaEE, JavaSE, and JavaME. He is a writer for Java.net and Javaworld.com on various topics, including JSF, Spring Security, Hibernate Search, and Spring Web Flow. He also has a physics PhD background with several publications in both high energy and condensed matter fields.

Preface

Spring Web Flow is an open-source web development framework and part of the Spring product portfolio. Its primary purpose is to define the (work) flow of a web application. The flow is independent of the implementation and thus the infrastructure of your application. This enables developers accustomed with Spring Web Flow to write powerful and re-usable web applications that are easy to maintain and enhance. Along with the Spring Web Flow distribution, additional libraries are shipped. These libraries make it easier for developers to improve their applications with compelling AJAX functionality. It also includes Spring Faces, which combines Spring Web Flow with the powerful JavaServer Faces technology to create feature-rich graphical user interfaces. You will find explanations about all this and much more in this book.

What this book covers

Chapter 1: Introduction gives an introduction to the world of Spring Web Flow. Additionally, the chapter covers important definitions that you need to know to understand the following chapters.

Chapter 2: Setup for Spring Web Flow 2 shows how to install Spring Web Flow and create the first small application. It also shows the usage of the examples that are provided in the Spring Web Flow distribution.

Chapter 3: The Basics of Spring Web Flow 2 covers all the basics that are essential to build applications with Spring Web Flow. It also explains all the essential things about the flow definition file.

Chapter 4: Spring Faces gives an overview and also a detailed explanation on the usage of Spring Faces with Spring Web Flow. For better understanding, it also explains the essential basics around JavaServer Faces.

Chapter 5: Mastering Spring Web Flow covers advanced topics, for example, the usage of subflows and the new Spring JavaScript library that ships with Spring Web Flow for the first time. The chapter also covers an in-depth look into the flow definition file.

Chapter 6: Testing Spring Web Flow Applications covers the important topic of testing applications that are developed with Spring Web Flow. It shows the integrated support of JUnit (http://www.junit.org) and includes step-by-step instructions showing how to test your applications.

Chapter 7: Security shows how to secure applications that are developed with Spring Web Flow using Spring Security.

Appendix A: flow.trac—The Model for the Examples describes the classes in the sample project, flow.trac. These classes are used in the examples of this book.

Appendix B: Running on the SpringSource dm Server explains how to run a Spring Web Flow application on the SpringSource Application Platform (AP).

What you need for this book

For the examples in this book, we have used the following software packages:

Java Development Kit (JDK) 6Spring Web Flow 2.0.xEclipse 3.4.x and NetBeans 6.1Apache Tomcat 6.0.18Apache Ant 1.7.1 / Apache Ivy 2.0.0 RC1Apache Maven 2.0.9Microsoft® SQL Server 2008 Express EditionMicrosoft® SQL JDBC Database Driver 1.2Hibernate Core 3.3.1 GA, Hibernate Annotations 3.4.0 GA, and Hibernate EntityManager 3.4.0 GASpringSource dm Server 1.0.x

Who this book is for

This book is targeted at Java web application developers who work with Spring Web Flow. This book is a must-read for those who wish to bridge the gap between the popular web framework and the popular application framework, and also for those who want to create powerful and re-usable web applications. It requires prior knowledge of Spring.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Next, we define a custom view resolver with a special viewClass property."

A block of code will be set as follows:

<dependency> <groupId>org.springframework.webflow</groupId> <artifactId>org.springframework.js</artifactId> <version>2.0.5.RELEASE</version> </dependency>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be shown in bold:

<end-state id="success" commit="true" /> <end-state id="failedView" view="failedView.jspx" />

Any command-line input or output is written as follows:

mvn clean compile war:exploded

New terms and important words are shown in bold. Words that you see on the screen, in menus, or dialog boxes for example, appear in our text like this: "If you click on the Next button, a request to the server will be sent which renders a new web site using Tiles."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to <[email protected]>, and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email <[email protected]>.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/5425_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or web site name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. Introduction

Nearly every day you read about a new release of a framework for developing web based applications. The Spring Framework is no exception. What makes Spring Web Flow(SWF) (second version, unless explicitly mentioned otherwise) special is that this framework not only solves one part of the tasks that have to be done in the development of a web application, but also helps you organize the flow (the order in which pages are called) inside your web application. Additionally, it manages the storage of data. However, to build a complete web application, you need more than Spring Web Flow. Therefore, we will also explain how to integrate Spring Web Flow with other frameworks.

Note

This book is neither a reference documentation, nor does it replace the reference documentation of the Spring Web Flow Framework. If you are interested in the reference documentation, we strongly recommend the reference from SpringSource. It is available online at the Uniform Resource Locator (URL) http://static.springframework.org/spring-webflow/docs/2.0.x/reference/html/index.html. If you need more information about the Spring Framework, visit the web page of the framework at the URL http://www.springframework.org.

Tip

If you need more help with your daily development of frameworks from the Spring Portfolio, please visit http://www.springsource.org/. The site provides more information about all of the different frameworks. If the available reference documentation is insufficient for your needs, you can search the forums that are offered on that page. The start page for the forums is http://forum.springsource.org/.

Besides the theoretical basics of the Spring Web Flow Framework, we will show you many examples in the later chapters. For the examples, we have chosen a bug-tracking application because it is common to have a bug tracker inside a software project. We developed some model classes, which we will use in all our examples. All the classes are shown in the Appendix A1: flow.trac—The Model for the Examples. You can use the classes under the Apache License Version 2.0. For more information about the license, please visit http://www.apache.org/licenses/LICENSE-2.0.html.

In this chapter, we will give a brief introduction to the essential modules of the complete Spring Framework stack: Spring, Spring MVC, and Spring Web Flow. Then we will explain the Spring Web Flow elements: flow, view, and conversation. This will be followed by the new features and modules of Spring Web Flow 2.0.

Three cornerstones: Spring, Spring MVC, and Spring Web Flow

Before we start explaining and writing an application with the Spring Web Flow Framework, we want to give you a small overview of the essential modules of the complete Spring Framework stack. You should know these for writing an application based on the Spring Web Flow Framework. The three cornerstones are:

Spring FrameworkSpring MVCSpring Web Flow

We will visualize the three cornerstones in the following figure:

Spring Framework

The Spring Framework is the base for all other modules (frameworks) inside the Spring portfolio. It was initially developed as a dependency injection container (this principle is also known as inversion of control). Besides the dependency injection, the second cornerstone of the Spring Framework is aspect-oriented programming (AOP).

The current version of the Spring Framework is far more than that. It is the base for a complete stack for building enterprise Java applications.

Spring MVC

Spring Model—View—Controller (MVC) is the base for web framework from SpringSource. It provides a complete implementation of the widely known Model—View—Controller pattern.

Spring Web Flow

Spring Web Flow is the framework that is covered in this book. It is possible to use Spring Web Flow without Spring MVC, but the integration with this framework is seamless.

What is Spring Web Flow

Whenever you read about Spring Web Flow on the Internet, you will find the expression conversational—you can use Spring Web Flow to create conversational web applications.

But what does that expression mean? It means that a user can interact with the application in a quite natural way. The application asks for information. After you have entered it, you can send it back to the application, which processes the data. In most cases, the application asks for more information.

For example, take an application with a wizard-like interface. Usually, wizard-like applications consist of multiple pages that are displayed one after the other. You can enter some information and then proceed to the next page, where you can enter additional information. If you think you've made mistakes, you can always go back to the previous page. Take a look at the data you have entered and correct them if they are wrong. Although you can go back any time you like, you can use the application only in the way the authors intended it to be used. You are working in a predefined flow with a specific goal, such as ordering a book or creating a new user account.

Although you can definitely write applications with this behavior using different technologies (even with pure Spring MVC), Spring Web Flow makes it very easy to create flows. Flows created by Spring Web Flow are not only decoupled from the applications logic, but are also re-usable in different applications. A flow in Spring Web Flow is a sequence of steps, that is, with states and transitions between them. There are also actions that can be executed on various points, for example, when the flow starts or a web page is rendered.

We have already mentioned that each flow exists for the purpose of reaching a defined goal. This means that you can use Spring Web Flow for all kinds of web applications with a predefined outcome such as user registration or login forms.

Note

Use the latest version of Spring Web Flow 2

We started writing this book with an early version of Spring Web Flow. While writing, some minor versions of Spring Web Flow were released (for example: 2.0.3, 2.0.4, and 2.0.5). It is highly recommended to use the latest available version of the framework. To see the fixes, you can look into the bug tracker for the Spring projects available at http://jira.springsource.org.

The elements of Spring Web Flow: flow, view, and conversation

Around the Spring Web Flow Framework there are three important words, which have to be defined:

FlowViewConversation

Flow

A flow is a self-contained business process representing a real-world use case. Typically, a flow consists of some views, and the data is stored inside a conversation. From a more technical viewpoint, a flow encapsulates a re-usable sequence of steps that can be executed in different contexts.

First, the flow describes the order and the requirements when the views are shown. Additionally, actions can be executed. Between the executions of a flow, a conversation holds the data of the user.

View

A view in Spring Web Flow is a single page that visualizes information.

Conversation

In traditional web applications, you have the scopes: request, session, and application. Many use cases in a web application consist of more than one page. Therefore, you need more than the request instance to store the data. A request is often not enough, and a session is too much. For this case, Spring Web Flow introduces the concept of a conversation.

For better understanding, we will visualize the conjunction of these three important concepts in the following figure:

The Spring Web Flow elements: an example

Now that we have described the three cornerstones—flow, view, and conversation, we want to explain the three elements and their relationship in a small example.

Imagine we have a portal where the user has to log in to see the content of the portal. We have the following three pages: login.xhtml, portal.xhtml, and error.xhtml. The login.xhtml is the page that is shown if the user is not logged into the portal. If the user is successfully logged in, the portal.xhtml page is shown. If the login fails, the error.xhtml page is shown. The following figure shows an example page flow:

The flow describes both the circumstances: a successful login and an unsuccessful login. Moreover, the transitions between the pages are described. The single pages (login.xhtml, portal.xhtml, and error.xhtml) are the views inside the flow. The conversation holds the data until a flow is executed. In the given example, the conversation stores the instance of an example class, User.

The new major release: Spring Web Flow 2.0

In mid-2008, Version 2.0, the new major version of Spring Web Flow was released. The following list shows a few main features of the new version:

A domain-specific language for defining re-usable controller modules called flowsAn advanced controller engine for managing conversational statesFirst-class support for using Ajax to construct rich user interfacesFirst-class support for using JavaServer Faces with Spring

If you download the Spring Web Flow 2.0 distribution (http://www.springframework.org/download), you will get the following four modules:

Spring Web FlowSpring FacesSpring JavaScriptSpring Binding

The following figure visualizes the structure for the 2.0.3 distribution of Spring Web Flow:

Spring Web Flow

Spring Web Flow is a framework in itself. It manages the handling of the flow with its conversation and views.

Spring Faces

Spring Faces is the module that connects Spring Web Flow with the JavaServer Faces (JSF) technology.

Spring JavaScript

Spring JavaScript is an encapsulation to add functionality on the client side to HyperText Markup Language (HTML) elements, for example, to add Asynchronous JavaScript and Extensible Markup Language (AJAX) features to the elements.

Spring Binding

Spring Binding is a library that helps you to bind data to the elements. This library is used internally by Spring Web Flow.

Introduction to a new version

To those readers who are familiar with the older version of Spring Web Flow, we want to give a small overview on what has really changed from Version 1.

The following concepts were added to the mentioned release of the Spring Web Flow Framework:

Automatic model bindingSupport for a new expression languageFlash scope is now a real Flash scopeSpring FacesFlow managed persistenceExternal redirects

A complete list of features is shown in Chapter 12 of the reference documentation of Spring Web Flow 2. This documentation is available online at http://static.springframework.org/spring-webflow/docs/2.0.x/reference/html/ch12.html.

Automatic model binding

In Version 1 of Spring Web Flow, you had to manually do the binding for your model classes. For this version, the class FormAction (package org.springframework.webflow.action) exists. The most notable methods are setupForm and bindAndValidate (see the following example).

<view-state id="display" view="sampleView"> <render-actions> <action bean="formAction" method="setupForm"/> </render-actions> <transition on="submit" to="show"> <action bean="formAction" method="bindAndValidate"/> </transition> </view-state>

The new release of Spring Web Flow now supports an automatic model binding through the usage of the model attribute inside the view-state.

Support for a new expression language

In Spring Web Flow 1, only Object-Graph Navigation Language (OGNL) is supported as an Expression Language (EL) within the flow definition files. Now support for the Unified EL is added. OGNL, of course, is still supported.

Flash scope is now a real flash scope

In Version 1 of Web Flow, the flash scope lived across the current request and into the next request. This is similar to the view scope inside the Version 2 of Spring Web Flow. In Web Flow 2, the flash scope is cleared after every view render. Now the flash scope is consistent with other web frameworks.

Spring Faces

The integration of JavaServerFaces is significantly improved with Ajax-enabled, custom JavaServer Faces (JSF) UICommand components, and an event-driven, action-binding approach. The name of the module is Spring Faces.

Flow managed persistence

Inside a web application, you have to deal with data: you have to read them from a database and store them to a database. Spring Web Flow offers the concept of flow managed persistence. With this feature, a flow can create, commit, and close an object persistence context for you. The framework integrates with both the object persistence technologies: Hibernate and Java Persistence API (JPA). (For more information on Hibernate Framework, visit http://www.hibernate.org; for more information on JPA read the Java Persistence FAQ from Sun available at http://java.sun.com/javaee/overview/faq/persistence.jsp.)

External redirects

The external redirects inside Spring Web Flow 1 were always relative to the context. Now in Spring Web Flow 2, if the redirect begins with a slash, it is considered to be servlet relative, rather than context relative. URLs without a leading slash are still considered context relative.

Summary

This chapter covers a brief overview of the new major release of Spring Web Flow. We mentioned the use of a bug-tracking application for the examples, which we will show in the following chapters.

In this chapter, we also explained the three frameworks: Spring, Spring MVC, and Spring Web Flow. The three cornerstones of Spring Web Flow—flow, view, and conversation—were also explained using practical examples. For the example, we assumed a login to a portal. Last, but not the least, we showed you the new features that are offered by Spring Web Flow 2. In the following chapter, we will explain how to install Spring Web Flow 2 and show an example that you can run on your local machine. With this example, you will get an idea of how to build your own web application using Spring Web Flow 2.

Chapter 2. Setup for Spring Web Flow 2

Now that we have covered the basics, it is time to actually write the first real application with Spring Web Flow. The typical example most books cover is the (in)famous Hello World example. We thought you would like something more sophisticated, so we decided to show you how you can design and implement a very simple login form. But first, we will explain how to install the Spring Web Flow 2 distribution on your computer. We will also show you which tools exist for you as a developer, and how you can integrate Spring Web Flow with your Integrated Development Environment (IDE). This will make it much easier to actually implement the example application.

There are certain prerequisites for the installation of a Spring Web Flow application, which we want to show you in this chapter as well. When you write your own application, you just have to take a look at this chapter and you will find all the information you need to start coding.

Installation of Spring Web Flow 2

Spring Web Flow 2 is available as a free download on the Spring project web site at http://www.springsource.com/download/community?project=Spring Web Flow. Additionally, as Spring Web Flow is an open source project, you can download the most up-to-date sources from the projects source code repository. While the core Spring project uses CVS (Concurrent Versions System) to manage the source code, Spring Web Flow uses Subversion (see http://subversion.tigris.org for more information on Subversion). Downloading the sources gives you an inside look at how Spring Web Flow really works, and even permits you to contribute to the project. If you are interested in using the source, you can find information on how to access the repository at http://sourceforge.net/svn/?group_id=73357. As you can see a little later in this chapter, the source code is also included in the binary distribution, in case you do not need the latest sources.

There are two variants of the Spring Web Flow distribution. You can either download it with all of the dependencies (spring-webflow-2.0.5.RELEASE-with-dependencies