Spring Web Flow 2.3.1

Table of Contents

Spring Web Flow 2.3.1 and ICEfaces 3.0.1

  Name Size Creator (Last Modifier) Creation Date Last Mod Date Comment  
ZIP Archive booking-icefaces.zip 324 kB Greg Dick Mar 28, 2012 Mar 28, 2012 Spring webflow tutorial with ICEfaces 3.0.1
Java Source WebflowListener.java 2 kB Greg Dick Sep 05, 2012 Sep 05, 2012 Webflow Flow Execution Listener

About Spring Web Flow

Spring Web Flow is a library that extends Spring MVC to user defined "controllers using a domain-specific-language." Web Flow is appropriately used when several actions need to be performed in order for a greater action to be performed (booking a hotel, or a flight for instance).

About This Tutorial

This tutorial borrows heavily on existing JSF tutorials for Spring Web Flow. Along the lines of JSF 2.1.0-b04 or so, JSF introduced some methods in the FacesContext class whose default implementation was to throw an UnsupportedOperationException.Spring has not (as of this writing) released a new version of Webflow to address these changes, so to combine Spring webflow, JSF, and ICEFaces required an odd concoction of older versions. Furthermore, ICEfaces 3 required a newer version of JSF, meaning ICEfaces 3 wasn't at all compatible with Spring Webflow 2.3.0.

Spring Source community has now resolved https://jira.springsource.org/browse/SWF-1467, and a fix is available through Maven using a snapshot build. The pom.xml file included in the download bundle refers to the nightly build of 26 March that has is known to work, but this should be updated to the general release once it's released.

The purpose of this tutorial is to demonstrate how application developers can use both Spring Webflow 2.3.1 and ICEfaces 3 in the same application. Both technologies leverage the Servlet API. Understanding how the various parts of the web.xml file are organized to accomodate both frameworks is essential to understanding this tutorial and being able to extend it to meet your own requirements.

This tutorial uses Spring Webflow 2.3.1 (prerelease build), Spring Security 3, Spring 3.0.5, JSF 2.1.3 and ICEfaces 3.0.1. Additional libraries are needed to support these frameworks and have been noted in the tutorial's build.xml or pom.xml file. This tutorial also has been tested with the Spring Web Flow 2.2.1 library as well. The JSF version in the attached tutorial is 2.1.3.

Tutorial Use Case

The simple business case for this tutorial the Spring Web FLow standard "booking application". Users can search for hotels and (after authenticating) book a room. Authenticated users can also review their bookings. This tutorial borrows heavliy from the Spring Web Flow sample booking application.

Issue with NULL ViewId and WindowID

There is an issue with the Spring implementation of the Lifecycle that affects the operation of ICEfaces. The ICEfaces BridgeSetup class uses a JSF PhaseListener to restore certain scope variables into the request map. Spring webflow applications, by default, use a POST->Redirect->GET pattern for navigation, but during the subsequent GET operation, the Spring lifecycle implementation does not appear to be executing the phase listeners during the RESTORE_VIEW phase. Side effects of this problem are the following symptoms:

1) Console messages of the following form:

SEVERE - Missing view ID attribute. Request map cleared prematurely.

SEVERE - Missing window ID attribute. Request map cleared prematurely.

2) NPE trying to rewrite a NULL viewID into the document:

at org.icefaces.impl.util.DOMUtils.isWhitespaceText(DOMUtils.java:394)
at org.icefaces.impl.util.DOMUtils.printNode(DOMUtils.java:351)
at org.icefaces.impl.util.DOMUtils.printNode(DOMUtils.java:355)
at org.icefaces.impl.util.DOMUtils.printNode(DOMUtils.java:355)

While the booking tutorial does not take advantage of windowScope, it is clear that functionality is reduced. There is a solution, and that is to use a WebflowListener to duplicate the missing phaseListener functionality. The booking-icefaces tutorial uses the com.icesoft.spring.security.WebflowListener (which is an instance of FlowExecutionListenerAdapter) class to this end. You can download a copy of this Listener directly from the link above, and it is also contained and configured in the tutorial. Configuration of the Listener is shown in the webflow-config.xml configuration section below.

Building the Tutorial War

The booking-icefaces tutorial is located in the icefaces/tutorials directory in the ICEfaces source distribution. It can be built either with ant or maven.

Configuration Areas:

  1. Configure Your Web.xml For Spring (Core, Web Flow, and Security)
  2. Configure Spring Core
  3. Configure Spring Web Flow
  4. Configure Spring Security

Part 1: Configure Web.xml For Spring

The web.xml below provides (in order) configuration parameters for JSF, filter configurations for spring security, Spring and JSF Servlet declarations and listeners.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"

    <!-- Use JSF view templates saved as *.xhtml, for use with Facelets -->

    <!-- Enables special Facelets debug output during development -->

    <!-- Causes Facelets to refresh templates during development -->

    <!-- Enforce UTF-8 Character Encoding -->


    <!-- Enables Spring Security -->


    <!-- Loads the Spring web application context -->

    <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>

    <!-- Map all /spring requests to the Dispatcher Servlet for handling -->
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>

        <servlet-name>Icefaces Resources Servlet</servlet-name>
    <!-- Just here so the JSF implementation can initialize, *not* used at runtime -->
        <servlet-name>Faces Servlet</servlet-name>

        <servlet-name>Icefaces Resources Servlet</servlet-name>

    <!-- Just here so the JSF implementation can initialize -->
        <servlet-name>Faces Servlet</servlet-name>



Part 2: Configure Spring Security

This step builds upon the configurations we put into the web.xml file. The two files shown in this step are the general
spring configuration and the security configuration.

The file immediately below (applicationContext.xml) includes 4-other spring configurations for security, webflow, database, and webmvc.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

	<!-- Scans for application @Components to deploy -->
	<context:component-scan base-package="org.springframework.webflow.samples.booking" />

	<!-- Imports the configurations of the different infrastructure systems of the application -->
	<import resource="config/webmvc-config.xml"  />
	<import resource="config/webflow-config.xml" />
	<import resource="config/data-access-config.xml" />
	<import resource="config/security-config.xml" />


Part 3: Configure Spring Web Flow

This step provides an overview of what needs to go into the Spring Web Flow configuration file to integrate well with ICEfaces 3. The configuration directs Spring Web Flow to look in the /WEB-INF/flows/*/-flow.xml pattern for web flow declarations. The tutorial application has two of these files which manage the main use case (create reservation) and the secondary use case (booking management). Note also the definition and references to the ICEfaces webflow listener.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd
           http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces.xsd">

	<!-- Executes flows: the central entry point into the Spring Web Flow system -->
	<webflow:flow-executor id="flowExecutor">
			<webflow:listener ref="facesContextListener"/>
			<webflow:listener ref="securityFlowExecutionListener" />
                        <webflow:listener ref="icefacesFlowListener" />

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

	<!-- Configures the Spring Web Flow JSF integration -->
	<faces:flow-builder-services id="facesFlowBuilderServices" development="true" />

	<!-- Installs a listener that creates and releases the FacesContext for each request. -->
	<bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

	<!-- Installs a listener to apply Spring Security authorities -->
	<bean id="securityFlowExecutionListener" class="org.springframework.webflow.security.SecurityFlowExecutionListener" />

        <!-- Define the ICEFaces webflow listener to restore window Scope -->
        <bean id="icefacesFlowListener" class="com.icesoft.spring.security.WebflowListener" />

Part 4: Configure Spring Security

Configuring Spring Security to work properly with ICEfaces 2 requires configurations not included in other JSF-based Spring Webflow tutorials. This is due to the design decision to leverage Spring Security's configurable "redirectStrategy" property.
In the file below we explicitly configure the redirect strategy used by Spring Security to send AJAX redirects if the request is AJAX driven (contains an AJAX header).

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"

    <!-- Configure Spring Security -->
    <http auto-config="false"

        <form-login login-page="/spring/login"
                    default-target-url="/spring/main" always-use-default-target="true"
                    authentication-failure-url="/spring/login?login_error=1" />

        <!-- When using custom filters, please make sure the positions do not conflict with default filters.
            Alternatively you can disable the default filters by removing the corresponding child elements from
            http and avoiding the use of http auto-config='true'. -->

        <custom-filter ref="exceptionTranslationFilter" before="FILTER_SECURITY_INTERCEPTOR" />

        <logout logout-url="/spring/logout" logout-success-url="/spring/logoutSuccess"/>
        <intercept-url pattern="/secure" method="POST" access="hasRole('ROLE_SUPERVISOR')"/>

		Define local authentication provider, a real app would use an external provider (JDBC, LDAP, CAS, etc)

		usernames/passwords are:
            <password-encoder hash="md5"/>
                <user name="keith" password="417c7382b16c395bc25b5da1398cf076"
                      authorities="ROLE_USER, ROLE_SUPERVISOR"/>
                <user name="erwin" password="12430911a8af075c6f41c6976af22b09"
                      authorities="ROLE_USER, ROLE_SUPERVISOR"/>
                <user name="jeremy" password="57c6cbff0d421449be820763f03139eb" authorities="ROLE_USER"/>
                <user name="scott" password="942f2339bf50796de535a384f0d1af3e" authorities="ROLE_USER"/>

    <beans:bean id="sessionManagementFilter"
        <beans:constructor-arg name="securityContextRepository" ref="httpSessionSecurityContextRepository" />
        <beans:property name="invalidSessionUrl" value="/auth/sessionExpired.jsf" />
        <beans:property name="redirectStrategy" ref="jsfRedirectStrategy" />

    <!-- http://static.springsource.org/spring-security/site/docs/3.1.x/reference/core-web-filters.html -->
    <beans:bean id="exceptionTranslationFilter" class="org.springframework.security.web.access.ExceptionTranslationFilter">
      <beans:property name="accessDeniedHandler" ref="jsfAccessDeniedHandler"/>
      <beans:property name="authenticationEntryPoint" ref="authenticationEntryPoint"/>

    <beans:bean id="jsfAccessDeniedHandler" class="com.icesoft.spring.security.JsfAccessDeniedHandler">
        <beans:property name="loginPath" value="/spring/login" />
        <beans:property name="contextRelative" value="true" />

    <beans:bean  id="authenticationEntryPoint" class="com.icesoft.spring.security.JsfLoginUrlAuthenticationEntryPoint">
        <beans:property name="loginFormUrl" value="/spring/login"/>
        <beans:property name="redirectStrategy" ref="jsfRedirectStrategy" />
    </beans:bean >

    <beans:bean id="jsfRedirectStrategy" class="com.icesoft.spring.security.JsfRedirectStrategy"/>
    <beans:bean id="httpSessionSecurityContextRepository" class="org.springframework.security.web.context.HttpSessionSecurityContextRepository"/>



Spring Web Flow 2.3 Documentation

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2021 ICEsoft Technologies Canada Corp.