Spring webflow与tiles.xml集成

时间:2016-02-18 04:43:20

标签: spring-webflow tiles spring-webflow-2

我有一个带有login-flow.xml的spring webflow项目,就像这样

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

    <view-state id="start" view="login.xhtml/>
    <end-state id="end" />
</flow>

问题是,如何通过tiles.xml中定义的视图名称替换视图状态中的视图?

之类的东西
<view-state id="start" view="login"/>

tiles.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
    "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
    <definition name="base.definition"
        template="/WEB-INF/layout/layoutgreen/baseLayout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="topHeader" value="/WEB-INF/layout/layoutgreen/topHeader.xhtml"/>
        <put-attribute name="header" value="/WEB-INF/layout/layoutgreen/header.xhtml" />
        <put-attribute name="menu" value="/WEB-INF/layout/layoutgreen/menu.xhtml" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/layout/layoutgreen/footer.xhtml" />
    </definition>

    <definition name="login" extends="base.definition">
        <put-attribute name="title" value="Login" />
        <put-attribute name="header" value="/WEB-INF/layout/layoutgreen/lheader.jsp" />
        <put-attribute name="body" value="/WEB-INF/flows/login/login.xhtml" />
    </definition>

</tiles-definitions>

由于

1 个答案:

答案 0 :(得分:0)

Apache tile完全按照您所描述的方式使用spring webflow

但是,您需要启用webflow才能使用apache磁贴以使其正常工作

请查看下面的配置以了解如何继续

<bean id="tilesViewResolver"
    class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
</bean>
<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">

        <list>
            <value>/WEB-INF/layouts/default.xml</value>
        </list>
    </property>
</bean>

<webflow-config:flow-registry id="flowRegistry"
        base-path="/WEB-INF/flows"
        flow-builder-services="flowBuilderServices">
    <webflow-config:flow-location 
        id="contact" path="contact-flow.xml">
    </webflow-config:flow-location>
</webflow-config:flow-registry>

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

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

<bean id="flowHandlerMapping" class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry"></property>
    <property name="order" value="0"></property>
</bean>

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

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

<bean id="validator"
    class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
</bean>