【问题标题】:Apache Tiles: abstract definition extending another abstract oneApache Tiles:抽象定义扩展另一个抽象定义
【发布时间】:2011-11-29 21:27:17
【问题描述】:

我正在使用 Tiles 2.2,我想重用一个 JSP 来显示不同的消息。消息必须在 Tiles 配置文件中定义。

以下示例是我的方法:base 是所有其他定义扩展的基本抽象定义,而 display 将是另一个抽象定义,用作显示的模板消息。 page1 和 page2 是两个最终页面示例,每个页面显示不同的消息。

<definition name="base" template="layout.jspx"/>

<definition name="display" extends="base">
        <put-attribute name="body" value="display.jspx"/>
</definition>

<definition name="page1" extends="display">
        <put-attribute name="message" value="This is one message!"/>
</definition>

<definition name="page2" extends="display">
        <put-attribute name="message" value="This is another message!"/>
</definition>

display.jspx 里面会有这样的东西:

<tiles:useAttribute name="message"/>
Message: ${message}

但我无法让它工作,因为当打开 page1 或 page2 时,我得到一个异常消息属性为空。

有没有一种简单的方法来设置这样的东西,无需修改基本模板和定义?

提前致谢

【问题讨论】:

  • 我已经有一段时间没有使用 Tiles 了。我想我记得必须将 type="string" 放在字符串类型的属性上。

标签: jsp tiles2 apache-tiles


【解决方案1】:

可能为时已晚,但我相信您需要将cascade="true" 添加到put-attribute 元素中以获取name="message"。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2011-10-08
    • 2018-08-17
    • 2017-05-30
    • 1970-01-01
    相关资源
    最近更新 更多