开发者

Using Spring Webflow + Tiles: How to specify which tiles definition to use at runtime?

I have a web application running开发者_如何学C with Spring Webflow, Tiles and JSP.

Currently all pages are extending my "defaultLayout" definition (which has a banner, menu structure, footer, etc.).

In tiles definition file:

<definition name="defaultLayout" template="/WEB-INF/tiles/defaultLayout.jsp"/>

<definition name="_**.view.jsp" extends="defaultLayout">
    <put-attribute name="content" value="{1}.view.jsp"/>
</definition>

A new requirement is to have an "embedded" view (without footer/menu/etc.). I created an embedded view definition:

<definition name="embeddedLayout" template="/WEB-INF/tiles/embeddedLayout.jsp"/>
<definition name="_**.embedded.view.jsp" extends="embeddedLayout">
    <put-attribute name="content" value="{1}.view.jsp"/>
</definition>        

I have JSP files that specify the main content of a page (all named: pageName.view.jsp).

Now what I need is some way to let tiles render pageName.embedded.view.jsp (which will use embeddedLayout) instead of pageName.view.jsp based on a certain requirement (haven't figured out that yet probably a request parameter passed in or something to that effect).

I am not too familiar with the inner workings of tiles What class can I override to change pageName.view.jsp to rather be pageName.embedded.view.jsp?

Here are my relevant Spring configuration:

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

<bean id="webflowViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    <property name="viewResolvers">
        <bean class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
            <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
            <property name="prefix" value="_"/>
        </bean>
    </property>
</bean>

Any help will be appreciated.

Tiles version: 2.2.1 Spring version: 3.0.3 Webflow version: 2.1.1


In the end I did the following which solved my problem (hopefully this will help others with a similar problem):

I decided that everything that has /embedded/ in the context path should use the embedded tile layout.

I extended org.springframework.js.ajax.AjaxUrlBasedViewResolver to check if the incoming request (retrieved using Spring's RequestContextHolder) contains /embedded/. If it does it changes the viewName to be whatever.embedded.view.jsp (instead of just whatever.view.jsp. It is then rendered using the embedded layout.

This solves my problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜