Question

I've recently started upgrading some applications to use Spring Webflow 2, and I want to make use of the new Ajax functionality that comes with Webflow 2. Can somebody please direct me to a tutorial for integrating Tiles 2 with Spring Webflow (since that's apparently what they recommend). I've found the documentation that comes with Webflow 2 in this regard to be absolutely useless.

Was it helpful?

Solution

This is what I did to get it working with webflow 2 and tiles 2.0

<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles-defs/templates.xml</value>
        </list>
    </property>
</bean>

<bean id="urlMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="/flow/**/*.html">
                flowController
            </prop>
            <prop key="/**/*.html">viewController</prop>
        </props>
    </property>
    <property name="order" value="1" />
</bean>

<bean id="tilesViewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>

<bean id="flowController"
    class="org.springframework.webflow.mvc.servlet.FlowController">
    <property name="flowExecutor" ref="flowExecutor" />
</bean>

<webflow:flow-executor id="flowExecutor"
    flow-registry="flowRegistry" />

<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices"
    base-path="/WEB-INF/flow/user">
    <webflow:flow-location path="/manage-users.xml" />
</webflow:flow-registry>


<webflow:flow-builder-services id="flowBuilderServices"
    view-factory-creator="viewFactoryCreator" />

<bean id="viewFactoryCreator"
    class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    <property name="viewResolvers" ref="tilesViewResolver" />
</bean>

OTHER TIPS

This isn't exactly referring to the ajax features, but it helped me get apache tiles 2 set up for regular flows:

http://jee-bpel-soa.blogspot.com/2008/12/spring-web-flows-2-and-tiles.html

A lot more details are at the link, but the core bit you need is a new view resolver:

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions" value="/WEB-INF/flows/main/main-tiles.xml" />
</bean>

It's perfectly explained in the docs. So, please, stop saying it isn't.

http://static.springsource.org/spring-webflow/docs/2.0.x/reference/htmlsingle/spring-webflow-reference.html

How to use tiles in spring: 10.5 View resolution (link + #spring-mvc-config-spring-view-resolution)

How to use Ajax with tiles in spring: 11.5: Handling Ajax request (link + #spring-js-ajax)

Copy the code from those links and you will end up with something like this:

Configuration for webflow to use Tiles:

    <!-- Plugs in a custom creator for Web Flow views -->
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" />

<!-- Configures Web Flow to use Tiles to create views for rendering; Tiles allows for applying consistent layouts to your views -->
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    <property name="viewResolvers" ref="tilesViewResolver" />
</bean>

Configuration for Tiles:

    <!-- Configures the Tiles layout system -->
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/views/layouts/page.xml</value>
            <value>/WEB-INF/views/layouts/table.xml</value>
            <value>/WEB-INF/views/globalViews.xml</value>
            <value>/WEB-INF/views/userViews.xml</value>
        </list>
    </property>
</bean>

Configuration for Tiles + Ajax:

    <!--
  - This bean configures the UrlBasedViewResolver, which resolves logical view names 
  - by delegating to the Tiles layout system. A view name to resolve is treated as
  - the name of a tiles definition.
  -->
<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView" />
</bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top