Installation Wiki

Setup for Spring Web Flow 2

From InstallationWiki

Jump to: navigation, search
Setup for Spring Web Flow 2
Official Page
Project Documentation
Download
Source Book
200px-1847195423.jpg
ISBN 978-1-847195-42-5
Publisher Packt Publishing
Author(s) Sven Lüppken, Markus Stäuble

This tutorial will explain how to install the Spring Web Flow 2 distribution on your computer, alongwith the tools that exist for you as a developer, and also 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 tutorial as well. When you write your own application, you just have to take a look at this tutorial and you will find all the information you need to start coding.

Contents

[edit] 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 tutorial, 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), or without any dependencies (spring-webflow-2.0.x.RELEASE). We'll explain the differences between the two distributions while looking at the folder layout of the extracted archive.

[edit] Inside the distribution

In this tutorial, we will give you an overview of the binary distribution of Spring Web Flow. After you've downloaded the files from the location mentioned in the previous section, you can use your favorite ZIP tool to unzip the distribution file. The folder layout looks like the one shown in the following screenshot in both the distributions:

In the dist folder, you can find the actual distribution of Spring Web Flow. It includes the JAR files that you can use in your applications. Using these libraries, you can have access to all the features that Spring Web Flow offers developers.

The docs folder includes documentation of the project. In this folder, you can find a reference guide in both HTML and Portable Document File (PDF) formats that covers the most important topics of Spring Web Flow.

The sources of Spring Web Flow and all related projects (such as requirements for building web applications and even the sources of the reference guide), as well as example applications are included in the projects folder.

The src folder provides you with the JAR files, which include the source code. You can use these, for example, in Eclipse to attach the source code.

You can use the F3 key on your keyboard on Spring Web Flow classes to jump into the source code. You will find this very useful when debugging applications.


In the distribution with dependencies, you can find an additional folder called ivy-cache in the projects folder:

This folder makes it easier to build examples of Spring Web Flow (explained later in this tutorial) wherein proxy servers or firewalls prohibit protocols other than say HTTP or HyperText Transfer Protocol Secure (HTTPS). As explained a little later, for each example in the distribution, the Amazon S3 protocol is used for the download. As you already have the dependencies of the examples, Ant (or its optional dependency manager, Ivy) doesn't have to download them from the Internet again.

As mentioned above, the distribution includes the reference documentation written by the Spring Web Flow developers. You can find additional information on the web site of the project (http://www.springframework.org/webflow). It explains the purpose of Spring Web Flow, and points to blog entries of the project's developers. Sadly, there is not much information available on the Internet. If you find a bug in Spring Web Flow, you can use the project's bug-tracking system at http://jira.springframework.org/browse/SWF. If you need help with a specific problem in your application, you can ask the Web Flow developers and other users using the project's forum, which you can access using the following URL: http://forum.springsource.org/forumdisplay.php?f=36.

[edit] The examples inside the distribution

If you download the distribution of the Spring Web Flow Framework, it includes the source code for five example projects. All examples implement the same web application. The differences between the sample applications would be in the technical fundaments used in them. The example application is a web application that simulates the booking of a hotel. The name of the demo hotel-booking application is Spring Travel. The application is available for online browsing at http://richweb.springframework.org/swf-booking-faces/spring/intro. The following screenshot shows the sample screen of the Spring Faces reference application.

After the extraction of the latest distribution of Spring Web Flow 2, you should see a projects folder. Inside this folder, you will find a root example folder, spring-webflow-samples. The layout of this folder should appear as shown in the following screenshot:

As mentioned earlier, each of the five example applications (each folder inside the spring-webflow-samples folder is an application) implements the same web application, Spring Travel. The technology base used is described in the following table:

Name of the folder Description of the technical base used in the example
booking-faces The Spring Travel application using the following technologies: Spring MVC, Spring Web Flow, Spring Faces, and Spring Security working together with JavaServer Faces (JSF) and Facelets
booking-mvc The Spring Travel application using the following technologies: Spring MVC, Spring JavaScript, Spring Web Flow, and Spring Security working together with JavaServer Pages (JSP) and Tiles
booking-portlet-faces The Spring Travel application based on booking-faces for a Portlet environment
booking-portlet-mvc The Spring Travel application based on booking-mvc for a Portlet environment
jsf-booking The example jsf-booking is to show you the solution for the integration of JSF and Spring with the Spring Faces module; the example uses the JSF-centric approach for the integration; the artifacts from JSF such as JSF controller model, JSF managed beans, and JSF navigation rules are used; Spring is used for the realization of the service layer; this example is only for comparison between a normal JSF application and a JSF application with Spring Faces and Spring Web Flow 2

[edit] Building the examples from the source code

The examples inside the distribution are provided as source files. This section explains how to build those examples.

The requirements to build the examples are:

  • Apache Ant Version 1.7 or higher (if you need more information about Apache Ant, or you want to download the latest release, visit the web page of Apache Ant at http://ant.apache.org)
  • Java SDK 5 or higher

If your local machine fulfills these requirements, the build is very simple. We need to set an environment variable for Ant. Go to the Control Panel, click on the System to open the System Properties. Select the Advanced tab and click on the Environment Variables which will open the Environment Variables window. Click on New to create a new environment variable. Set the Variable name to ANT_HOME and the Variable value to the folder path pointing to your Ant root folder. Similarly, modify the PATH environment variable to include the %ANT_HOME%\bin folder. Now, go to the projects/build-spring-webflow folder from the command line and execute the ant command. Now, the projects start to build. If you have downloaded the distribution without dependencies, the essential libraries are downloaded with the dependency manager, Apache Ivy, which is included in the distribution. In these projects, the Amazon S3 protocol is used for the download. If you are having problems with the download of the dependencies, it could be a proxy problem. You can change the configuration in the projects/spring-build/lib/ivy/jets3t.properties file. If you need more information about the configuration, please read the document at http://jets3t.s3.amazonaws.com/toolkit/configuration.html#jets3t.

The examples are provided as binary file too

In case you have problems in building the examples, or that you do not want to build it on your own, the examples have also been provided as binary files. For that, you can download the examples as WAR archive from http://www.springsource.org/webflow-samples. On that page, all the examples are provided, except the jsf-booking example application.

After a successful build, the binaries of the samples are located inside the target folder of each example application. The artifacts subdirectory contains the WAR file of the application. The war-expanded subfolder contains the complete web application in a folder variant.

The following figure shows the folder layout of the example application, booking-faces. The other examples look similar to this:

[edit] Installing the examples on your local machine

After you have the binaries, the installation is as simple as with the other applications on your preferred application server. In our case, we have used the latest version of Apache Tomcat, which you can download from http://tomcat.apache.org. For Apache Tomcat, you just have to drop the WAR file, and build into the webapps folder of the installation. Now, you can access the web application on your local machine.

If you are new to Spring Web Flow 2, installing an example (such as booking-faces) on your local machine is highly recommended. With these examples, you can include your own steps by changing some files in the examples. It helps you get a quick overview of the functionality of Spring Web Flow 2.


Importing projects to Eclipse

In Eclipse, you can import an existing project by clicking on File | Import....This should display the Import window. Click on Existing Projects into Workspace under General folder. Click on Next, enter the folder path of the target project in the Select root directory field and click on Finish.

[edit] Source

The source of this content is Chapter 2: Setup for Spring Web Flow 2 of Spring Web Flow 2 Web Development by Sven Lüppken, Markus Stäuble (Packt Publishing, 2009).

Personal tools