在瓷砖拼图模板,为什么在属性中包含的模板未定义? [英] Nesting templates in Tiles, why are attributes undefined in the included template?

查看:99
本文介绍了在瓷砖拼图模板,为什么在属性中包含的模板未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用瓷砖2在我的web应用程序,以及基本设置我在我的tiles.xml文件得到是这样的:

I use Tiles 2 in my web application, and the basic setup I've got in my tiles.xml file is this:

<tiles-definitions>
    <definition name="mainLayout" template="/jsp/layout.jsp">
        <put-attribute name="header" value=""/>
        <put-attribute name="menu" value="/jsp/defaultMenu.jsp" />
        <put-attribute name="content" value="" />
        <put-attribute name="footer" value="/jsp/footer.jsp" />
    </definition>

    <definition name="HomePage" extends="mainLayout">
        <put-attribute name="content" type="template" value="/jsp/home.jsp"/>
        <put-attribute name="homeClass" value="active" />
    </definition>

    ... rest omitted for brevity.

在layout.jsp,它定义了布局,我包括在适当的位置的菜单

In layout.jsp, which defines the layout, I include the menu in the appropriate place.

<tiles:insertAttribute name="menu" />

所以,后来我的菜单模板里面,我想用在tiles.xml定义的homeClass属性。

So, then inside my menu template, I wanted to use the homeClass attribute defined in tiles.xml.

<tiles:insertAttribute name='homeClass'/>

但我得到属性没有被定义有关homeClass错误。如果我在layout.jsp做一个insertAttribute,该值被正确定义,但我需要它在菜单JSP,从我的布局包括定义。

but I get an error about the homeClass attribute not being defined. If I do an insertAttribute in my layout.jsp, the value is defined properly, but I need it defined in the menu JSP, included from my layout.

所以,我的问题是:我怎么能有正确地传递不只是我的布局模板的 homeClass 属性,但菜单模板这是从布局模板包含

So, my question is: How can I have the homeClass attribute passed correctly not just to my layout template, but to the menu template which is included from the layout template?

推荐答案

我相信你可以使用嵌套的模板定义:

I believe you could use nested template definitions:

<definition name="mainLayout" template="/jsp/layout.jsp">
        <put-attribute name="header" value=""/>

        <put-attribute name="menu">
            <definition template="/jsp/defaultMenu.jsp">
                <put-attribute name="homeClass" value="active"/>
            </definition>
         </put-attribute>

        <put-attribute name="content" value="" />
        <put-attribute name="footer" value="/jsp/footer.jsp" />
    </definition>

这篇关于在瓷砖拼图模板,为什么在属性中包含的模板未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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