From Documentation

Jump to: navigation, search



Define and configure Spring Webflow to be used with ZK Spring Webflow.


For introducing ZK Spring Webflow we have borrowed from standard Spring Webflow booking-mvc application that you can download from here. We have modified it to use ZK as a presentation layer and also demonstrate ZK Spring integration library features.

You can see this sample application in action below

It has two flows;main and booking. Main flow is what users use to search hotels and view their details. Booking flow is what users use to book specific hotel by registering themselves and entering their booking details.

Before we define and implement these webflows we need to configure Spring Webflow to be able to discover these cofigurations. Lets see how we can achieve that in the following section.


First we register our flows definitions with Spring Webflow flowRegistry in webflow-config.xml as shown below

    <!-- The registry of executable flow definitions -->
    <webflow:flow-registry id="flowRegistry"
        <webflow:flow-location id="main" path="/WEB-INF/flows/main/main.xml" />
        <webflow:flow-location id="booking" path="/WEB-INF/flows/booking/booking.xml" />

This example uses persistence layer to store booking information in the database and it is achieved by using Spring Webflow's org.springframework.webflow.persistence.JpaFlowExecutionListener.

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


    <!-- Installs a listener that manages JPA persistence contexts for flows that require them -->
    <bean id="jpaFlowExecutionListener"
        <constructor-arg ref="entityManagerFactory" />
        <constructor-arg ref="transactionManager" />

As described in the previous section, this example uses Spring Webmvc to implement main and booking flows. We define flow request URIs to their Spring MVC controllers mappings in webmvc-config.xml as shown below

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

    <!-- Maps request URIs to controllers -->             
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
        <property name="defaultHandler">
            <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    <!-- Maps logical view names to ZK templates (e.g. 'search' to '/WEB-INF/search.zul' -->
    <bean id="viewResolver" class="org.zkoss.spring.web.servlet.view.ZkResourceViewResolver">
        <property name="prefix" value="/WEB-INF/"/>
        <property name="suffix" value=".zul"/>

Flow definitions

Now moving on to the actual flow definitions, first we define main flow that used to search for hotels and view hotel details. There are four view states; enterSearchCriteria, reviewHotels, reviewHotel and changeSearchCriteria. It also defines a subflow state bookHotel that refers to booking subflow (defined in booking.xml). Lets take a look at a gragment from main.xml that defines enterSearchCriteria view state and booking subflow.

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns=""
    <var name="searchCriteria" class="" />
    <view-state id="enterSearchCriteria">
            <evaluate expression="bookingService.findBookings(" result="viewScope.bookings" />
        <transition on="search" to="reviewHotels">
            <evaluate expression="searchCriteria.resetPage()" />
        <transition on="cancelBooking">
            <evaluate expression="bookingService.cancelBooking(" />
            <render fragments="bookingsFragment" />
    <subflow-state id="bookHotel" subflow="booking">
        <input name="hotelId" value="" />
        <transition on="bookingConfirmed" to="finish" />
        <transition on="bookingCancelled" to="enterSearchCriteria" />
    <end-state id="finish" />

You can see the full source code of main.xml here.

As you can see the main flow starts with earching for hotel i.e. by viewing enterSearchCriteria state. <on-render /> child element of it specifies certain back-end operation such as booking search to be performed on rendering the state. It also specifies if the result of this operation is stored into a variable in a specific scope such as bookings in viewScope. <view-state /> elements also specify transitions to other states using <transition /> child elements. This main flow also starts a booking subflow as specified by <subflow-state /> element.

the booking sub-flow is defined in a similar way with certain view-states and their transitions. you can take a look at booking.xml that defines this subflow here

Version History

Last Update : 2012/12/10

Version Date Content

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.