我对使用Struts2的Tiles 3有疑问。我似乎无法覆盖嵌套tile-definition的属性。
这是我的web.xml的相关部分:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
这是我的struts.xml
<package name="helloworld" extends="tiles-default" namespace="/secure">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" default="true" />
</result-types>
<interceptors>
<interceptor name="s2sLogging" class="com.s2s.web.s2.S2Interceptor" />
<interceptor-stack name="s2sStack">
<interceptor-ref name="timer" />
<interceptor-ref name="defaultStack" />
<interceptor-ref name="s2sLogging" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="s2sStack" />
<action name="howitworks" class="com.s2s.web.s2.S2RootAction" >
<result name="success" type="tiles">.howItWorks.landing</result>
</action>
这是我的tiles.xml
<definition name="s2s.rightNav" template="/WEB-INF/s2/pages/common/rightNav.jsp" >
</definition>
<definition name="s2s.pageContent" template="/WEB-INF/s2/pages/pageContent.jsp">
<put-attribute name="box" value="true" /> <!-- change to false to remove grey box behind text -->
<put-attribute name="rightNav" value="s2s.rightNav" />
</definition>
<!-- overall page layout -->
<definition name="page.layout" template="/WEB-INF/s2/pages/page.jsp">
<put-attribute name="pageTitlePrefix" value="s2s.com" type="string"/>
<put-attribute name="pageTitle" value=" " type="string"/>
<put-attribute name="headContent" value="s2s.headContent" />
<put-attribute name="extraHeadContent" value=".tile.empty" />
<put-attribute name="topNav" value="s2s.topNav" />
<put-attribute name="topNavSubNav" value="s2s.topNavSubNav" />
<put-attribute name="pageContent" value="s2s.pageContent" />
<put-attribute name="footer" value="s2s.footer" type="string"/>
<put-attribute name="SEOkeywords" value="s2s, ship to storage, moving storage services, self-storage, moving storage, self storage shipping, send to storage, ship to self storage, shipping storage, mail storage, self storage pick up and delivery" />
<put-attribute name="SEOdescription" value="The worlds most convenient self-storage. s2s combines shipping, elf storage, and service -- prices from $2.79 a box. Boxes are picked up from your doorstep and stored at our climate controlled, secure warehouse. s2s's flexible pricing grows as your needs grow. A valuable shipping and storage resource for moving, relocation, offices, students, trade shows, and more." />
<put-attribute name="pageSEOkeywords" value=" " type="string"/>
<put-attribute name="pageSEOdescription" value="s2s.com - " type="string"/>
<put-attribute name="debugPage" value="v.101" type="string"/>
</definition>
<!-- PAGE DEFNINITIONS -->
<definition name=".howItWorks.landing" extends="page.layout">
<put-attribute name="pageTitle" value="How Mail Storage Works " type="string"/>
<put-attribute name="selectedTab" value="howItWorks" type="string"/>
<put-attribute name="pageSEOkeywords" value="how it works, " type="string"/>
<put-attribute name="pageSEOdescription" value="How It Works | " type="string"/>
<put-attribute name="rightNavCTAs" value="estimateBoxSize,helpfulLinks" type="string" cascade="true"/>
<put-attribute name="mainBodyContent" value="s2s.howItWorks.MainBodyContent" cascade="true"/>
</definition>
<definition name="s2s.howItWorks.MainBodyContent" template="/WEB-INF/s2/pages/howItWorks.jsp" />
我希望使用 .howItWorks.landing 的定义覆盖 mainBodyContent 和 rightNavCTAs 属性。但是,当我在jsp中打印出实际值时,rightNavCTAs为null(我认为这意味着即使我使用cascade =&#34; true&#34;),该值也不会向下传播。
根据Apache Tiles 3文档here,我应该能够使用上面的子定义进行嵌套,然后扩展和覆盖属性。级联应该传播属性。
毋庸置疑,我无法让它发挥作用。谁能发现我的缺陷?
as Requested,这是我的jsps。谢谢你的期待。
所有jsps都在顶部:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
这是我的page.jsp(剥离了css):
<tiles:importAttribute scope="request"/>
<html>
<head>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/stylesheet.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/jmesa.css">
<title>
<tiles:getAsString name="pageTitlePrefix" /> - <tiles:getAsString name="pageTitle" />
</title>
<tiles:insertAttribute name="headContent" />
<tiles:insertAttribute name="extraHeadContent" />
</head>
<body>
<div id="page">
<tiles:insertAttribute name="topNav" />
<tiles:insertAttribute name="topNavSubNav" />
<tiles:insertAttribute name="pageContent" />
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>
以下是 pageContent.jsp (剥离了css):
<table >
<tr>
<td >
<!-- Box Table Starts here-->
<s:if test="%{#attr['box'] == 'true'}">
<table >
<tr>
<td /></td>
<td /></td>
<td /></td>
</tr>
<tr>
<td > </td>
<td >
<!-- Insert Main Body Content1 -->
<tiles:insertAttribute name="mainBodyContent" />
<!-- End of Main Body Content1 -->
</td>
<td > </td>
</tr>
<tr>
<td /></td>
<td > </td>
<td /></td>
</tr>
</table>
</s:if>
<s:else>
<!-- Insert Main Body Content -->
<tiles:insertAttribute name="mainBodyContent" />
<!-- End of Main Body Content -->
</s:else>
</td>
<td > </td>
<td >
<tiles:insertAttribute name="rightNav" />
</td>
</tr>
</table>
<!-- End Page Content -->
这是我的 howitworks.jsp (再次,剥离了css)。这应该覆盖 mainBodyContent 属性,但我无法使其工作:
<table >
<tr>
<td />Test... how it works</td>
<td /></td>
<td /></td>
</tr>
</table>