views:

3151

answers:

3

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.

+1  A: 

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>
TM
Thank you kindly for your response, but unfortunately it's really not any more useful than the documentation provided with SWF 2. I did eventually get it working, though I really had to hack around and play with things a lot to figure out things that weren't said in the SWF 2 documentation. If anybody wants help with SWF2, they're more than welcome to contact me at alexmarshall132 at gmail dot com
Alex Marshall
I'd definitely be interested to know what you had to do to get it to render tiles definitions directly in a view state. At the moment I have resorted to just rendering jsps that just have <tiles:insertDefintion>. Not a solution that I particularly like.
TM
I defined a JSP that I wanted to use as the decoration for all my pages, ie with navbar, logout link, etc. In that page I use a <tiles:insertAttribute name="body"/> tag. Then I have all my Tiles <definition name="myView" extends="main"><put-attribute name="body" value="/WEB-INF/path/to/my.jsp"/></definition>. I have a <definition name="main" template="/WEB-INF/path/to/my/template.jsp"/> from which all the other definitions extend.
Alex Marshall
+1  A: 

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>
+1  A: 

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>