阿帕奇砖 - 如何覆盖从子模板属性 [英] apache tiles - how to override an attribute from child template

查看:169
本文介绍了阿帕奇砖 - 如何覆盖从子模板属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我怎么能覆盖瓦子模板的属性。

The question is how can I override an attribute in tiles child template.

我有两个模板:基地和孩子。这是基地布局的一部分 - HTML头:

I've got two templates: base and child. This is a part of base layout - HTML head:

<title>
    <tiles:insertAttribute name="title" />
    lyricsBase: <c:out value="${jukebox.name}" />
</title>

这是我的tiles.xml:

This is my tiles.xml:

<definition name="t.base" template="/WEB-INF/tiles/base.jsp">
    <put-attribute name="title" value="SomeTitle"/>
</definition>
[...]
<definition name="t.song" extends="t.base">
    <put-attribute name="body" value="/WEB-INF/jsp/song.jsp"/>
    <put-attribute name="title" value="song.title"/>
</definition>

当我跑我的网页,我获得以下HTML标题: song.title lyricsBase:XXX 。什么code我应该把到子视图覆盖标题属性?我试图让它$ {} song.title,例如:

When I run my page, I get following HTML title: song.title lyricsBase: xxx. What code should I put into the child view to override the title attribute? I'm trying to make it ${song.title}, for example

<tiles:putAttribute name="title" value="${song.title}" />

...但它不工作。感谢您的帮助!

...but it doesn't work. Thanks for any help!

推荐答案

您不应该使用的价值属性,但除权pression属性。在tiles3我有与认沽属性的字符串值,而不级联是真实的问题......这是假设tiles3(虽然大多是适用于大多数的瓷砖2)。

You should not be using the value attribute but the expression attribute. In tiles3 I was having an issue with string values for put attributes without cascade being true... This assumes tiles3 (although most is applicable to most of tiles 2).

以下是未经测试的:

<definition name="t.base" template="/WEB-INF/tiles/base.jsp">
    <put-attribute name="title" cascade="true" value="SomeTitle"/>
</definition>
[...]
<definition name="t.song" extends="t.base">
    <put-attribute name="body" value="/WEB-INF/jsp/song.jsp"/>
    <put-attribute name="title"  cascade="true" expression="EL:song.title"/>
</definition>

然后&LT;地砖:insertAttribute名称=标题/&GT; 应该如预期在模板中工作。

Then <tiles:insertAttribute name="title" /> should work as expected in your template.

这篇关于阿帕奇砖 - 如何覆盖从子模板属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆