SpringMVC 3 和 Tiles 2 页面标题本地化
我有一个使用 Spring 3、Apache Tiles 2 和 Maven 的项目设置。 在实现 Tiles 之前,我使用 messages.properties 文件动态填充网页的标题(出现在 head 和 title 标签之间的部分)。这样做的原因是为了将来允许本地化。然而,由于我集成了图块,tiles.xml 文件似乎控制了我的页面的标题。
有没有办法更改此设置,以便页面标题来自我用作页面正文的每个 jsp 的 messages.properties?
tiles.xml 是:
<definition name="base.definition" template="/WEB-INF/views/layouts/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/views/includes/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/views/includes/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/includes/footer.jsp" />
</definition>
<definition name="home" extends="base.definition">
<put-attribute name="title" value="Welcome from Tile" />
<put-attribute name="body" value="/WEB-INF/views/home.jsp" />
</definition>
<definition name="new-deal-input" extends="base.definition">
<put-attribute name="title" value="New Deal" />
<put-attribute name="body" value="/WEB-INF/views/new-deal-input.jsp" />
</definition>
当您看到“Welcome from Tile”或“New Deal”作为标题时,我宁愿这条消息来自 messages.properties。我尝试将消息放入“正文”页面上的标题标签中,但无济于事。
该项目已在 GitHub 上安装,您可以查看以下 URL:Group-Deal-Clone
I have a project setup using Spring 3, Apache Tiles 2 and Maven.
Before I implement Tiles I was using the messages.properties file to dynamically populate the titles for a webpage (The part that appears between the head and title tags). The reason for this was to allow localization in the future. However since I've integrated tiles, the tiles.xml file seems to control the titles for my page.
Is there a way to change this so the page title comes from messages.properties for each jsp I use as the body of a page?
tiles.xml is:
<definition name="base.definition" template="/WEB-INF/views/layouts/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/views/includes/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/views/includes/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/includes/footer.jsp" />
</definition>
<definition name="home" extends="base.definition">
<put-attribute name="title" value="Welcome from Tile" />
<put-attribute name="body" value="/WEB-INF/views/home.jsp" />
</definition>
<definition name="new-deal-input" extends="base.definition">
<put-attribute name="title" value="New Deal" />
<put-attribute name="body" value="/WEB-INF/views/new-deal-input.jsp" />
</definition>
Where you see "Welcome from Tile" or "New Deal" as the title I would rather that this message comes from a messages.properties. I've tried putting the message in the title tags on the "body" page to no avail.
The project is setup on GitHub, you can take a look at this URL: Group-Deal-Clone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一种变体,没有 c:set:
在tiles-defs.xml中:
在base.jsp中:
在messages.properties中:
Another variant, without c:set:
in tiles-defs.xml:
in base.jsp:
in messages.properties:
您可以将 springs 消息键放入tiles标题属性中。
并在jsp中使用它,就像这样
我现在手上没有tiles + spring项目,所以我无法检查语法是否100%正确,但我以前使用过这种方法。
当然,你可以这样做来获取每页标题
You can put springs message key to tiles title attribute.
and use it in jsp something like this
I don't have right now tiles + spring project on hands so I can't check is syntax 100% correct but I have use this approach before.
And of course you could do something like this to get per page title