从许多模板组成 Apache Tiles 2 布局

发布于 2024-10-16 02:23:31 字数 2708 浏览 8 评论 0原文

我正在使用 Spring 3 和 Tiles 2.2 构建 Web 应用程序。我已经放置了以下布局定义:

<tiles-definitions>  
<definition name="default" template="/WEB-INF/layouts/default.jspx">  
<put-attribute name="header" value="main.header" />  
<put-attribute name="top_menu" value="/WEB-INF/views/top_menu.jspx" />  
<put-attribute name="left_column" value="main2.left_column" />  
<put-attribute name="main_column" value="main2.main_column" />  
<put-attribute name="footer" value="/WEB-INF/views/footer.jspx" />  
</definition> 

<definition name="main2.main_column" template="/WEB-INF/layouts/double_column/main_column.jspx">  
</definition>

<definition name="main2.left_column" template="/WEB-INF/layouts/left_column.jspx">  
        <put-attribute name="profile_menu" value="/WEB-INF/views/userprofile/userdetails.jspx" />  
        <put-attribute name="common_menu" value="/WEB-INF/views/menu.jspx" />  
      </definition>  
</tiles-definitions>

在 WEB-INF/layouts/default.jspx

<div id="main_page" >   
    <tiles:insertAttribute name="left_column"/>    
    <tiles:insertAttribute name="main_column"/>   
        <div id="footer" >  
<tiles:insertAttribute name="footer" ignore="true"/>  
                </div>  
            </div>  

现在在 /WEB-INF/layouts/double_column/main_column.jspx 我有:

<tiles:insertAttribute name="body"/>  

请求的路径 view.xml 定义如下:

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

错误是:

org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found.
    org.apache.tiles.template.DefaultAttributeResolver.computeAttribute(DefaultAttributeResolver.java:49)
    org.apache.tiles.template.InsertAttributeModel.resolveAttribute(InsertAttributeModel.java:187)
    org.apache.tiles.template.InsertAttributeModel.start(InsertAttributeModel.java:107)
    org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:306)
    org.apache.jsp.WEB_002dINF.layouts.double_005fcolumn.main_005fcolumn_jspx._jspx_meth_tiles_005finsertAttribute_005f0(main_005fcolumn_jspx.java:79)
    org.apache.jsp.WEB_002dINF.layouts.double_005fcolumn.main_005fcolumn_jspx._jspService(main_005fcolumn_jspx.java:54)

如果我将“body”直接放入默认模板中,它可以工作,但问题是我希望我的模板砖可以被许多布局重用,而不仅仅是默认布局,而且我不想使用 main_column 将所有格式复制到每个模板定义,

请建议

I'm building the web application with Spring 3 and Tiles 2.2. I've put following layout definition:

<tiles-definitions>  
<definition name="default" template="/WEB-INF/layouts/default.jspx">  
<put-attribute name="header" value="main.header" />  
<put-attribute name="top_menu" value="/WEB-INF/views/top_menu.jspx" />  
<put-attribute name="left_column" value="main2.left_column" />  
<put-attribute name="main_column" value="main2.main_column" />  
<put-attribute name="footer" value="/WEB-INF/views/footer.jspx" />  
</definition> 

<definition name="main2.main_column" template="/WEB-INF/layouts/double_column/main_column.jspx">  
</definition>

<definition name="main2.left_column" template="/WEB-INF/layouts/left_column.jspx">  
        <put-attribute name="profile_menu" value="/WEB-INF/views/userprofile/userdetails.jspx" />  
        <put-attribute name="common_menu" value="/WEB-INF/views/menu.jspx" />  
      </definition>  
</tiles-definitions>

In WEB-INF/layouts/default.jspx

<div id="main_page" >   
    <tiles:insertAttribute name="left_column"/>    
    <tiles:insertAttribute name="main_column"/>   
        <div id="footer" >  
<tiles:insertAttribute name="footer" ignore="true"/>  
                </div>  
            </div>  

Now in /WEB-INF/layouts/double_column/main_column.jspx i have:

<tiles:insertAttribute name="body"/>  

Requested path view.xml is defined as following:

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

and error is:

org.apache.tiles.template.NoSuchAttributeException: Attribute 'body' not found.
    org.apache.tiles.template.DefaultAttributeResolver.computeAttribute(DefaultAttributeResolver.java:49)
    org.apache.tiles.template.InsertAttributeModel.resolveAttribute(InsertAttributeModel.java:187)
    org.apache.tiles.template.InsertAttributeModel.start(InsertAttributeModel.java:107)
    org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:306)
    org.apache.jsp.WEB_002dINF.layouts.double_005fcolumn.main_005fcolumn_jspx._jspx_meth_tiles_005finsertAttribute_005f0(main_005fcolumn_jspx.java:79)
    org.apache.jsp.WEB_002dINF.layouts.double_005fcolumn.main_005fcolumn_jspx._jspService(main_005fcolumn_jspx.java:54)

If i put "body" directly to the default template it works, but thing is I want have my template bricks being reusable by many layouts, not only default one and i dont want to copy all formating to each template definition using main_column

Please advice

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初雪 2024-10-23 02:23:31

由于异常告诉您 main_column 的定义没有属性 body。您的第二个定义表示它是您的根定义,而不是 main_column 的定义。默认情况下,不存在诸如属性继承或冒泡之类的东西。因此,孩子们对父母的属性一无所知,反之亦然。对于您的问题,有两种解决方案:

您可以将属性 cascade="true" 添加到属性定义中。这让属性级联到子定义(请参阅级联属性)

您可以使用嵌套定义:

<tiles-definitions>  
  <definition extends="default" name="secure/createAccount/*">  
    <put-attribute name="main_column">
      <definition template="/WEB-INF/layouts/double_column/main_column.jspx">
        <put-attribute name="body" value="/WEB-INF/views/secure/createAccount/{1}.jspx"/>  
      </definition>
    </put-attribute>
  </definition>  
</tiles-definitions>

(请参阅嵌套定义

As the exception tells you the definition of main_column has not attribute body. Your second definition says that it is an your root definition and not of main_column. By default there is no such thing like attributes inheritance or bubbling. Hence the children don't know anything about the attributes of their parents and vice versa. Their are two solutions for your problem:

You can add the attribute cascade="true" to your attribute definition. That lets the attribute cascade to the child definitions (see cascaded attributes)

You could use nested definitions:

<tiles-definitions>  
  <definition extends="default" name="secure/createAccount/*">  
    <put-attribute name="main_column">
      <definition template="/WEB-INF/layouts/double_column/main_column.jspx">
        <put-attribute name="body" value="/WEB-INF/views/secure/createAccount/{1}.jspx"/>  
      </definition>
    </put-attribute>
  </definition>  
</tiles-definitions>

(see nesting definitions)

牵你手 2024-10-23 02:23:31

可能您正在 web.xml 中的welcomepagelist 中指定baselayout.jsp 页面。如果您指定删除该请求并向操作类发送虚拟请求,则将您的响应转发到在tiles.xml中声明的某个jsp

May be you are specifying the baselayout.jsp page at welcomepagelist in web.xml. if you specified that one remove that and send dummy request to action class then forward your response to some jsp which is declared in tiles.xml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文