Config ZK Spring Webflow

From Documentation


Purpose

Setup ZK Spring Webflow

Prerequisite

ZK Spring Webflow depends on ZK Spring Core so any configuration for ZK Spring Core is a prerequisite for setting up ZK Spring Weblow.

Configuration

To enable ZK Spring Webflow in your application all you need to do is to include ZK Spring Core and ZK Spring Webflow libraries in your application classpath by copying them to your web project WEB-INF/lib folder.

Here we will describe some configurations needed to setup a ZK Spring Webflow example that is described in the following sections. In our example Spring Webflow is used in conjunction with Spring MVC hence first we need to declare Spring MVC servlet configurations in the web.xml file.

    <!-- The master configuration file for this Spring web application -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/config/web-application-config.xml
        </param-value>
    </context-param>
    <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
        
    <!-- Map all *.spring requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/spring/*</url-pattern>
    </servlet-mapping>

Here contextConfigLocation is where Spring MVC will look for application specific configuration files which are described in the next sections. Lets take a look at our web-application-config.xml file.

<?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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- Activates annotation-based bean configuration -->
    <context:annotation-config />
    
    <!-- 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="webmvc-config.xml" />
    <import resource="webflow-config.xml" />
    <import resource="data-access-config.xml" />
    <import resource="security-config.xml" />

</beans>

Since this example uses Spring core, Spring Security and Spring Webmvc in addition to Spring Webflow we have a separate configuration file for each. We import all these separate configuration files into this one single file.

For now the most important configuration file for configuring ZK Spring Webflow is webflow-config.xml which is where we mention ZK Spring Webflow specific configuration to enable its features support for ZK and Spring Webflow integration.

<?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:webflow="http://www.springframework.org/schema/webflow-config"
    xmlns:zksp="http://www.zkoss.org/2008/zkspring/webflow"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd 
    http://www.zkoss.org/2008/zkspring/webflow
    http://www.zkoss.org/2008/zkspring/webflow/zkspring-webflow.xsd">

    <!-- 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>


    <!-- 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>

    <!-- 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>

    <!-- Installs a listener to apply Spring Security authorities -->
    <bean id="securityFlowExecutionListener"
        class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
        
    <!-- Configures the ZK Spring Web Flow integration -->
    <zksp:flow-controller id="flowController" flow-executor="flowExecutor"/>
    <zksp:flow-builder-services id="zkFlowBuilderServices" />
</beans>

Here we configure ZK Spring Webflow builder service and flow controller by specifying

    <zksp:flow-controller id="flowController" flow-executor="flowExecutor"/>
    <zksp:flow-builder-services id="zkFlowBuilderServices" />

Note that you need to declare ZK Spring Webflow namespace at the start of your configuration file.

and setting them up with standard Spring Webflow flowRegistry as shown below

    <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 is the minimum configuration you will need to enable ZK Spring Webflow support in you Spring Webflow applications

Version History

Last Update : 2022/01/19


Version Date Content
     


Last Update : 2022/01/19

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