如何在插入的页面中包含图块定义属性
我有一个包含这些定义的tiles-defs.xml...
<definition name="masterLayout" path="/WEB-INF/tiles-layouts/globalLayout.jsp">
<put name="pageTemplate" value="over-ride for each page" />
</definition>
<definition name="childLayout" extends="masterLayout">
<put name="pageTemplate" value="/WEB-INF/tiles-layouts/child/layout.jsp" />
<put name="title" value="page title" />
<put name="metaKeywords" value="" />
<put name="metaDescription" value="" />
<put name="body" value="/child/pagebody.jsp"/>
<putList name="list">
<add value="title" />
<add value="metaKeywords" />
<add value="metaDescription" />
<add value="body" />
</putList>
</definition>
在globalLayout.jsp中我可以正常工作,但我并不总是知道子定义已添加到页面中的属性。
<tiles:insert attribute="pageTemplate">
<tiles:put name="title"><tiles:getAsString name="title" /></tiles:put>
<tiles:put name="metaKeywords"><tiles:getAsString name="metaKeywords" /></tiles:put>
<tiles:put name="metaDescription"><tiles:getAsString name="metaDescription" /></tiles:put>
<tiles:put name="body"><tiles:getAsString name="body" /></tiles:put>
由于子定义并不总是包含相同的属性。有没有办法在子定义中使用 putList 将属性放入 globalLayout.jsp 内的子页面范围内?我尝试过以下方法,但失败了
<%@ page import="java.util.Iterator" %>
<tiles:importAttribute />
<bean:define id="list" name="list" type="java.util.List" scope="page" />
<tiles:insert attribute="pageTemplate" ignore="true" flush="true">
<%
for ( Iterator it = list.iterator(); it.hasNext(); ) {
String item = (String) it.next();
%>
<tiles:put name="<%=item%>"><tiles:getAsString name="<%=item%>" ignore="true" /></tiles:put>
<% } %>
</tiles:insert>
I have a tiles-defs.xml that has these definitions...
<definition name="masterLayout" path="/WEB-INF/tiles-layouts/globalLayout.jsp">
<put name="pageTemplate" value="over-ride for each page" />
</definition>
<definition name="childLayout" extends="masterLayout">
<put name="pageTemplate" value="/WEB-INF/tiles-layouts/child/layout.jsp" />
<put name="title" value="page title" />
<put name="metaKeywords" value="" />
<put name="metaDescription" value="" />
<put name="body" value="/child/pagebody.jsp"/>
<putList name="list">
<add value="title" />
<add value="metaKeywords" />
<add value="metaDescription" />
<add value="body" />
</putList>
</definition>
in globalLayout.jsp I have this working, but I won't always know what attributes the child definition has added to the page.
<tiles:insert attribute="pageTemplate">
<tiles:put name="title"><tiles:getAsString name="title" /></tiles:put>
<tiles:put name="metaKeywords"><tiles:getAsString name="metaKeywords" /></tiles:put>
<tiles:put name="metaDescription"><tiles:getAsString name="metaDescription" /></tiles:put>
<tiles:put name="body"><tiles:getAsString name="body" /></tiles:put>
Since the child definition won't always include the same attributes. Is there a way to use the putList in the child definition to put the attributes into the child page's scope inside of globalLayout.jsp? I've tried the following, but it fails
<%@ page import="java.util.Iterator" %>
<tiles:importAttribute />
<bean:define id="list" name="list" type="java.util.List" scope="page" />
<tiles:insert attribute="pageTemplate" ignore="true" flush="true">
<%
for ( Iterator it = list.iterator(); it.hasNext(); ) {
String item = (String) it.next();
%>
<tiles:put name="<%=item%>"><tiles:getAsString name="<%=item%>" ignore="true" /></tiles:put>
<% } %>
</tiles:insert>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Tiles 2,您现在可以在图块中的
put-attributes
上设置cascade="true"
。这将使它们对嵌套子模板可见。请参阅此处
With Tiles 2 you can now set
cascade="true"
onput-attributes
in tiles. This will make them visible to nested child templates.See here
我没有尝试将属性下推到子布局,而是将子布局拉到父布局的范围内。
instead of trying to push the attributes down to a child layout, I pulled the child layout up into the scope of the parent layout.