Define Flow

From Documentation
Revision as of 02:47, 25 February 2011 by Ashishd (talk | contribs)


Purpose

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

Example

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

demo

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.

Configuration

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"
        flow-builder-services="zkFlowBuilderServices">
        <webflow:flow-location id="main" path="/WEB-INF/flows/main/main.xml" />
        <webflow:flow-location id="booking" path="/WEB-INF/flows/booking/booking.xml" />
    </webflow:flow-registry>

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:flow-execution-listeners>
            <webflow:listener ref="jpaFlowExecutionListener" />
            <webflow:listener ref="securityFlowExecutionListener" />
        </webflow:flow-execution-listeners>
    </webflow:flow-executor>

...

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


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="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- Maps request URIs to controllers -->             
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <value>
                /main=flowController
                /booking=flowController
            </value>
        </property>
        <property name="defaultHandler">
            <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
        </property>
    </bean>
    
    <!-- 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"/>
    </bean>
</beans>


Version History

Last Update : 2011/02/25


Version Date Content
     


Last Update : 2011/02/25

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