0

来自http://tiles.apache.org/2.0/framework/tutorial/advanced/nesting-extending.html

<definition name="myapp.homepage.body" template="/layouts/three_rows.jsp">
  <put-attribute name="one" value="/tiles/headlines.jsp" />
  <put-attribute name="two" value="/tiles/topics.jsp" />
  <put-attribute name="one" value="/tiles/comments.jsp" />
</definition>

<definition name="myapp.homepage" template="/layouts/classic.jsp">
  <put-attribute name="title" value="Tiles tutorial homepage" />
  <put-attribute name="header" value="/tiles/banner.jsp" />
  <put-attribute name="menu" value="/tiles/common_menu.jsp" />
  <put-attribute name="body" value="myapp.homepage.body" />
  <put-attribute name="footer" value="/tiles/credits.jsp" />
</definition>

我需要扩展myapp.homepage,并且在该扩展定义中,我需要将另一个属性添加到 myapp.homepage.body. 希望它有意义。

4

2 回答 2

1

我终于能够解决这个问题。答案如下:

<definition name="myapp.homepage_extended" extends="myapp.homepage" >
  <put-attribute name="new-attr-in-body" value="/tiles/new-attr-in-body.jsp"  cascade="true" />
</definition>

诀窍是添加cascade="true",以便属性可以通过嵌套定义级联。

于 2013-11-01T14:03:52.873 回答
0
<definition name="myapp.homepage.extended" extends="myapp.homepage">
    <put-attribute name="yournewattribute" value="My New Attribute" />
</definition>

!-- Note: you can also use this pattern to override an attribute. All the other     attributes will remain:
<definition name="myapp.homepage.override" extends="myapp.homepage">
    <put-attribute name="tiele="My New Title" />
</definition>

!-- Or you can combine overrrides with additional attributes:
<definition name="myapp.homepage.custom" extends="myapp.homepage">
    <put-attribute name="tiele="My New Title" />
    <put-attribute name="yournewattribute" value="My New Attribute" />
</definition>
于 2013-10-30T22:04:20.690 回答