I am building a Struts Web application and I'm using Tiles for the first time. I have it all set up and working nicely. My problem comes in the fact that I want to use a standard messages.resources file for my page titles.
For example
home.title=Main Home Page
info.title=Intro Page
etc.
I am used to setting the bundle at the top of the page like:
<fmt:setBundle basename="messages"/>
and then directly accessing keys as follows:
<fmt:message key="home.title"/>
however I am now using tiles so what I had hoped was to use a tiles attribute to pass the key :
<definition name=".home" extends=".baseDef">
<put name="titleKey" value="title.home" />
</definition>
and then use the key in the tile like:
<fmt:message key="${titleKey}"/>
however, nothing I've tried has worked (including just trying the fmt:message tag w/o using Tiles like :
<c:set var="titleKey" value="home.title"/>) .
For some reason, the fmt:message tag refuses to accept exptession values.
Can anyone offer me a best practice on how to handle this? Or at least solve my problem?
-
Struts and Tiles and fmt:message key values (2 messages)
- Posted by: Vincent Fumo
- Posted on: March 25 2005 14:04 EST
Threaded Messages (2)
- Struts and Tiles and fmt:message key values by Rich Hill on March 25 2005 16:17 EST
- Struts and Tiles and fmt:message key values by Alexander Magdenko on March 28 2005 10:24 EST
-
Struts and Tiles and fmt:message key values[ Go to top ]
- Posted by: Rich Hill
- Posted on: March 25 2005 16:17 EST
- in response to Vincent Fumo
I'm not sure about using the resource file, but if you want to pass the value directly you should try
<definition name=".home" extends=".baseDef">
<put name="titleKey" value="Main Home Page" />
</definition>
and then
<tiles:getAsString name="titleKey"/>
in your jsp -
Struts and Tiles and fmt:message key values[ Go to top ]
- Posted by: Alexander Magdenko
- Posted on: March 28 2005 10:24 EST
- in response to Vincent Fumo
I make temporary solution for the same problem :)
in layout JSP put that code
<%
ComponentContext context = ComponentContext.getContext(request);
if (context == null) {
throw new ServletException("This must be called by a Tile, not directly");
}
String title = (String) context.getAttribute("titleKey");
if(title != null){
%>
<title><bean:message key="<%=title%>"/></title>
<%
}else{
%>
<title><bean:message key="index.title"/></title>
<%
}
%>