How to leave a tile empty
Is it possible to leave a tile empty? Let's say I have three tiles in a page: header, body, footer. Can i simply add a body and a footer and leave header empty?
<body class="claro">
<div id="wrapper">
<div id="container" class="container">
<div id="hd">
<tiles:insertAttribute name="header" />
</div>
<div id="bd">
<hr/>
<tiles:insertAttribute name="body" />
</div>
<div id="ft">
<hr/>
<tiles:insertAttribute name="footer" />
</div>
</div>
</div>
So I want to use this once like this :
<definition name="base" template="...">
<put-attribute name="header" value="/WEB-INF/views/base/header.jspx" />
<put-attribute name="body" value="/WEB-INF/views/base/body.jspx" />
<put-attribute name="footer" value="/WEB-INF/views/base/footer.jspx" />
</definition>
And once like this :
<definition name="base" template="...">
<put-attribute name="body" value="/WEB-INF/views/base/body.jspx" />
<put-attribute name="footer" value="/WEB-INF/views/base/footer.jspx" />
</definition>
Currently the second usage blows up. Saying i have开发者_如何学编程n't defined header.
Is there a way to do this?
Use the ignore attribute:
<tiles:insertAttribute name="header" ignore="true"/>
According to the docs:
If this attribute is set to true, and the attribute specified by the name does not exist, simply return without writing anything. The default value is false, which will cause a runtime exception to be thrown.
You could just provide an empty header page in a base definition and then replace body and footer in the more specific ones.
You could also just set the value to an empty string:
<put-attribute name="header" value=""/>
精彩评论