支柱2,图块2动态标题 [英] struts 2, tiles 2 dynamic title

查看:97
本文介绍了支柱2,图块2动态标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tile 2.0.6作为我的模板框架以及struts 2.1.6.我正在编写一个简单的cms页面,并希望让用户定义每个html页面的标题.

I am using tiles 2.0.6 as my template framework together with struts 2.1.6. I am writing a simple cms page and want to let the user to define the title of each html page.

我有这样的标题定义

    <definition name="base" template="/WEB-INF/jsp/templates/base.jsp">
        <put-attribute name="title" value=" "/>
        <put-attribute name="header" value="/WEB-INF/jsp/templates/header.jsp"/>  
        <put-attribute name="content" value="dummy"/>
        <put-attribute name="footer" value="/WEB-INF/jsp/templates/footer.jsp"/>   
        <put-attribute name="search" value="/WEB-INF/jsp/search.jsp"/>
    </definition>    
    <definition name="staticview" extends="base">
        <put-attribute name="title" value=" - Static"/>
        <put-attribute name="content" value="/WEB-INF/jsp/static/view.jsp"/>
    </definition>  

除了使标题成为jsp之外,还有一种方法可以在稍后的jsp属性中动态覆盖我的header.jsp上的标题(字符串),例如view.jsp.甚至可以再使用EL

Instead of making the title a jsp, is there a way to dynamically override the title (String) on my header.jsp in the later jsp attribute, for example view.jsp. Or even 1 step further using EL

<put-attribute name="title" value="%{title}"/>

让它动态地在struts ognl上获取标题.

and have it pick up the title on the struts ognl dynamically.

请告知

预先感谢

推荐答案

在视图页面中,我们需要拥有它-

In the view page we need to have this -

<title><tiles:getAsString name="title" /></title>

以上将为您获取页面标题.除此之外,由于我们希望页面标题是动态的,因此在tile.xml配置中,我添加了

Above will get you the title for the page. Except, since we want the page title to be dynamic, in the tiles.xml configuration, I added

<definition name="page1" extends="base">
    <put-attribute name="title" value="Page 1"/>
    <put-attribute name="content" value="/WEB-INF/jsp/page1.jsp"/>
</definition>
<definition name="page2" extends="base">
    <put-attribute name="title" value="Page 2"/>
    <put-attribute name="content" value="/WEB-INF/jsp/page2.jsp"/>
</definition>

现在看来,键入它会使它看起来像是静态的.但是,每次查看该页面时,该页面的标题都应该相同.在tile.xml上拥有此信息的更好的地方.

Now this may seem like typing it will make it look like it is static. But every time you view that page, the title should be the same for that page. What better place to have this information that on tiles.xml.

对我来说,这不是标题本身,但是我需要不同的页面标题.我不想查看context属性来获取页面的路径并确定页面的标题.因此,这对我有用,并使所有内容保持松散耦合.

For me it was not the title itself, but I needed different page headings. I didn't want to look at the context attribute to get the path of the page and determine the heading for the page. So, this worked for me and kept everything loosely coupled.

如果您要为每个页面或其他类似的页面使用不同的动态标题,则可以使用此功能.

这篇关于支柱2,图块2动态标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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