【问题标题】:How do I extend templates in tiles?如何在磁贴中扩展模板?
【发布时间】:2011-07-16 11:54:12
【问题描述】:

我有一个具有通用站点布局框架的主模板:“/WEB-INF/jsp/common.jsp” 然后我有另一个模板,该模板通常用于其他具有类似布局的页面:“/WEB-INF/jsp/features/common.jsp”

features 模板基本上定义了“master”模板的属性“content”的内容。

我尝试通过以下方式解决此问题:

<definition name="product.common" template="/WEB-INF/jsp/common.jsp">
    <put-attribute name="content" value="/WEB-INF/jsp/features/common.jsp" />
</definition>
<definition name="features/index" extends="product.common">
    <put-attribute name="title" value="Features" />
    <put-attribute name="rightContent" value="/WEB-INF/jsp/features/index.jsp" />
</definition>

但这不起作用。我在堆栈跟踪中收到以下错误消息:

org.apache.tiles.template.NoSuchAttributeException:找不到属性“rightContent”。

但 features-template 确实具有以下内容:

<tiles:insertAttribute name="rightContent" />

有什么想法吗?

【问题讨论】:

    标签: apache jsp tomcat tiles


    【解决方案1】:

    我猜你需要的是nesting definitions。你可以试试这样的。

    <definition name="features.common" template="/WEB-INF/jsp/features/common.jsp">
    </definition>
    
    <definition name="product.common" template="/WEB-INF/jsp/common.jsp">
        <put-attribute name="content" value="features.common" />
    </definition>
    
    <definition name="features/index" extends="product.common">
        <put-attribute name="title" value="Features" />
        <put-attribute name="rightContent" value="/WEB-INF/jsp/features/index.jsp" />
    </definition>
    

    【讨论】:

    • 这和我的有什么不同?
    • @Piotr。如果您仔细看,在我的示例中,内容包含一个 subdefinition
    • 好的,我试过了,结果“org.apache.tiles.template.NoSuchAttributeException: Attribute 'rightContent' not found.”。问题是“rightContent”在功能通用模板中。还有其他想法吗?
    • 解决方案是使用级联! :) 感谢您的帮助
    • @Piotr。如果您将您的答案添加到您的问题中会更好(如果您指向现有答案则更好:Propagating a Tiles attribute down the include chain)。正如您所说,接受的答案并没有指向正确的方向。
    猜你喜欢
    • 2020-01-25
    • 2021-02-18
    • 2022-10-24
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2019-10-11
    • 1970-01-01
    相关资源
    最近更新 更多