在包含链下传播Tiles属性 [英] Propagating a Tiles attribute down the include chain
问题描述
我正在使用Tiles,我希望为页面定义的属性在包含的子页面之一中可读,如下所示:
I'm using Tiles and I'd like an attribute defined for a page to be readable inside of one of the included subpages as follows:
tiles-definitions.xml
:
<definition name="page" template="/WEB-INF/tiles/layout/page.jsp">
<put-attribute name="header" value="/WEB-INF/jsp/_include/header.jsp"/>
<put-attribute name="footer" value="/WEB-INF/jsp/_include/footer.jsp"/>
</definition>
<definition name="tutorial" extends="page">
<put-attribute name="title" value="Tutorial"/>
<put-attribute name="body" value="/WEB-INF/jsp/tutorial.jsp"/>
</definition>
page.jsp
代表一个简单的页面结构:
The page.jsp
represents a simple page structure:
<html>
<head><title><tiles:getAsString name="title"/></title></head>
<body>
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="body"/>
<tiles:insertAttribute name="footer"/>
</body>
</html>
我也试图在标题"子页面中阅读标题,但出现以下错误:
I'm trying to read the title also inside the "header" subpage but I get the following error:
org.apache.tiles.template.NoSuchAttributeException:找不到属性标题".
org.apache.tiles.template.NoSuchAttributeException: Attribute 'title' not found.
这是我尝试访问header.jsp中的属性的方法:
Here is how I'm trying to access the attribute in header.jsp:
<tiles:getAsString name="title"/>
推荐答案
要将title
属性传播到内部模板,您需要将cascade="true"
属性添加到title
的<put-attribute>
标记中,如下所示:
To propagate the title
attribute to inner templates you need to add cascade="true"
attribute to the title
's <put-attribute>
tag, like this:
<definition name="tutorial" extends="page">
<put-attribute name="title" cascade="true" value="Tutorial"/>
<put-attribute name="body" value="/WEB-INF/jsp/tutorial.jsp"/>
</definition>
这篇关于在包含链下传播Tiles属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!