Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringMVC 3 and Tiles 2 Localization of Page Title

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

like image 655
Ali Avatar asked Aug 04 '11 07:08

Ali


1 Answers

Another variant, without c:set:

in tiles-defs.xml:

<definition name="index" template="/WEB-INF/tiles/base.jsp">
  <put-attribute name="title" value="home.title"/>
  <put-attribute name="header" value="/WEB-INF/includes/iheader.jsp"/>
  ...
</definition>

in base.jsp:

<head>
 <tiles:importAttribute name="title" />
 <title><spring:message code="${title}"></spring:message></title>
</head>

in messages.properties:

home.title=Homepage title
like image 177
Dmitry Avatar answered Oct 21 '22 02:10

Dmitry