开发者

Apache Tiles: how to access definition name

I want to write the tiles definition name direct into the templates. But I have no idea how to access the definition name.

To illustrate what I want to do have a look at this workaround:

<tiles-definitions>

  <definition extends="default" name="index">
    <put-attribute name="body" value="/WEB-INF/views/index.jspx"/>
    <put-attribute name="pageId" value="index"/> 开发者_如何学运维       
  </definition>

   <definition extends="default" name="login">
      <put-attribute name="body" value="/WEB-INF/views/login.jspx"/>
      <put-attribute name="pageId" value="login"/>
   </definition>
</tiles-definitions>

Default Template:

<html>
...
    <tiles:useAttribute id="tiles_pageId" name="pageId" classname="java.lang.String" />
    <body id="pageId_${tiles_pageId}">
...
    </body>
</html>

This works. I can specify an attribute (pageId) in the definition, read it in the template and write it in the template output.

But you see there is a 1:1 correlation between definition name and pageId. So I do not want to write the name twice (definition name and pageId) in the definition. Instead I am looking for a way to skip the pageId attribute declaration and get the definition name somehow else in the template (without writing it twice again and again.)


I think you can use Wildcard in your definition

<definition extends="default" name="*">
    <put-attribute name="body" value="/WEB-INF/views/{1}.jspx"/>
    <put-attribute name="pageId" value="{1}"/>
</definition>

More info here : http://tiles.apache.org/framework/tutorial/advanced/wildcard.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜