You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bob Arnott <bo...@aungate.com> on 2005/05/25 19:20:56 UTC
JSTL fmt:message with modules
Hello, just trying out JSTL on a new app I'm writing as I thought
it was about time I used it. However, I'm having a bit of trouble
with the <fmt:message /> tag as I don't know how to specify the
correct bundle to use.
I'm using modules and tiles, so each module has it's own resource
bundle, but they share the tiles templates. I'm trying to pass a
page title with a tiles definition and have it pulled from the
resource bundle and displayed. But I don't know how to tell the
<fmt:message /> tag which bundle to use...?
...
<title>
<tiles:useAttribute id="title" name="title" scope="page" />
<fmt:message key="${pageScope.title}" />
</title>
...
I've seen some web pages mention that you can put a context param
in the web.xml:
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>ApplicationResources</param-value>
</context-param>
But Shirley this wont work for modules...? Can anyone shed some
light on how I get this to work...?
Thanks,
--
Bob Arnott
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: JSTL fmt:message with modules
Posted by Bob Arnott <bo...@aungate.com>.
Martin Gainty wrote:
> BobThis tutorial from Nick Heudecker may helpAssuming you
> place
> ApplicationResources.properties,FrenchApplicationResources.properties
> in WEB-INF/classes<message-resources
> key="EnglishResources" parameter="ApplicationResources"/>
> <message-resources key="FrenchApplicationResources"
> parameter="FrenchApplicationResources"/>The most common
> Struts tag to use is the bean:message tag. This tag
> allows you to load a specific message resource from the
> bundle using the "key" attribute. It also allows you to
> populate any or all of the four arguments in the value:
> <bean:message bundle="FrenchApplicationResources"
> key="some.message.key"/>The html:message tag allows you
> to display errors (default) or messages to the user,
> while html:errors will only display error messages.
> Messages and errors must be present in the request,
> obviously, or there will be nothing to display. Here is
> an example of displaying the messages:
>
> <logic:messagesPresent message="true">
> <html:messages id="msg" message="true">
> <div class="success">
> <bean:write name="msg"/>
> </div><br/>
> </html:messages>
> </logic:messagesPresent>
> Anyone else?Martin
I'm not trying to display a different internationalised bundle,
I'm using JSTL not the Struts bean taglib. I want to know how the
<fmt:message /> tag will pick up the resource bundle key under
Globals.MESSAGE_KEY for each module while in a tiles template.
Cheers,
--
Bob Arnott
Software Developer
Autonomy Systems Ltd.
Cambridge Business Park
Cowley Road
Cambridge
CB4 0WZ
T: +44 (0) 1223 448 000
F: +44 (0) 1223 448 001
http://www.aungate.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: JSTL fmt:message with modules
Posted by Martin Gainty <mg...@hotmail.com>.
BobThis tutorial from Nick Heudecker may helpAssuming you place
ApplicationResources.properties,FrenchApplicationResources.properties in
WEB-INF/classes<message-resources key="EnglishResources"
parameter="ApplicationResources"/>
<message-resources key="FrenchApplicationResources"
parameter="FrenchApplicationResources"/>The most common Struts tag to use is
the bean:message tag. This tag allows you to load a specific message
resource from the bundle using the "key" attribute. It also allows you to
populate any or all of the four arguments in the value: <bean:message
bundle="FrenchApplicationResources" key="some.message.key"/>The html:message
tag allows you to display errors (default) or messages to the user, while
html:errors will only display error messages. Messages and errors must be
present in the request, obviously, or there will be nothing to display. Here
is an example of displaying the messages:
<logic:messagesPresent message="true">
<html:messages id="msg" message="true">
<div class="success">
<bean:write name="msg"/>
</div><br/>
</html:messages>
</logic:messagesPresent>
Anyone else?Martin------ Original Message -----
From: "Bob Arnott" <bo...@aungate.com>
To: "'Struts Users Mailing List'" <us...@struts.apache.org>; "'Martin
Gainty'" <mg...@hotmail.com>
Sent: Thursday, May 26, 2005 6:14 AM
Subject: RE: JSTL fmt:message with modules
> Martin Gainty wrote:
>> Bob-
>> assuming you set userLocale to english north america
>> <table bgcolor="#d0d0d0" cellspacing="0" cellpadding="5"
>> border="0" width="100%">
>> <tr>
>> <td>
>> <center> <h2>
>> <fmt:setLocale value="<%=userLocale%>"/>
>> <fmt:bundle
>> basename="com.abcbank.example.ApplicationResources">
>> <fmt:message key="header.title"/> </fmt:bundle>
>> </h2>
>> <br>
>> </td>
>> </tr>
>> </table>
>>
>> so in the jsp if variable userLocale is set as Locale
>> userLocale = new Locale("fr", "CA");
>> header.title key is located in
>> ApplicationResources_fr_CA.properties located on the
>> com/abcbank/example folder
>> and if header.title = Banque de Quebec
>> that is what you would see
>
> I'm not asking about locales, I'm asking how you tell the <fmt:message />
> tag which bundle to use when you have multiple default bundles as a result
> of having multiple modules.
>
> I currently have an application that has four modules, each with multiple
> resource bundles. I access the default resource bundles in each module:
>
> <bean:message key="message.key" /> or,
> <bean:message key="message.key" bundle="bundle.key" />
>
> Struts stores the bundles in the application scope with the module name
> appended to the Globals.MESSAGE_KEY constant, for example -
>
> org.apache.struts.action.MESSAGE/moduleOne
>
> I'm writing a new app and I've decided to use JSTL instead of the non
> struts-el tags. Now I probably didn't make myself clear in my last post,
> does Struts do something so that the <fmt:message /> tag works in a
> similar
> way, thus you can do:
>
> <fmt:message key="message.key" bundle="${Globals.MESSAGE_KEY}" />
>
> So that it doesn't matter what module you are in you'll get the right
> bundle...?
>
> Cheers,
>
> --
> Bob Arnott
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: JSTL fmt:message with modules
Posted by Bob Arnott <bo...@aungate.com>.
Martin Gainty wrote:
> Bob-
> assuming you set userLocale to english north america
> <table bgcolor="#d0d0d0" cellspacing="0" cellpadding="5"
> border="0" width="100%">
> <tr>
> <td>
> <center> <h2>
> <fmt:setLocale value="<%=userLocale%>"/>
> <fmt:bundle
> basename="com.abcbank.example.ApplicationResources">
> <fmt:message key="header.title"/> </fmt:bundle>
> </h2>
> <br>
> </td>
> </tr>
> </table>
>
> so in the jsp if variable userLocale is set as Locale
> userLocale = new Locale("fr", "CA");
> header.title key is located in
> ApplicationResources_fr_CA.properties located on the
> com/abcbank/example folder
> and if header.title = Banque de Quebec
> that is what you would see
I'm not asking about locales, I'm asking how you tell the <fmt:message />
tag which bundle to use when you have multiple default bundles as a result
of having multiple modules.
I currently have an application that has four modules, each with multiple
resource bundles. I access the default resource bundles in each module:
<bean:message key="message.key" /> or,
<bean:message key="message.key" bundle="bundle.key" />
Struts stores the bundles in the application scope with the module name
appended to the Globals.MESSAGE_KEY constant, for example -
org.apache.struts.action.MESSAGE/moduleOne
I'm writing a new app and I've decided to use JSTL instead of the non
struts-el tags. Now I probably didn't make myself clear in my last post,
does Struts do something so that the <fmt:message /> tag works in a similar
way, thus you can do:
<fmt:message key="message.key" bundle="${Globals.MESSAGE_KEY}" />
So that it doesn't matter what module you are in you'll get the right
bundle...?
Cheers,
--
Bob Arnott
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: JSTL fmt:message with modules
Posted by Martin Gainty <mg...@hotmail.com>.
Bob-
assuming you set userLocale to english north america
<table bgcolor="#d0d0d0" cellspacing="0" cellpadding="5" border="0"
width="100%">
<tr>
<td>
<center> <h2>
<fmt:setLocale value="<%=userLocale%>"/>
<fmt:bundle basename="com.abcbank.example.ApplicationResources">
<fmt:message key="header.title"/>
</fmt:bundle>
</h2>
<br>
</td>
</tr>
</table>
so in the jsp if variable userLocale is set as Locale userLocale = new
Locale("fr", "CA");
header.title key is located in ApplicationResources_fr_CA.properties located
on the com/abcbank/example folder
and if header.title = Banque de Quebec
that is what you would see
Martin-
----- Original Message -----
From: "Bob Arnott" <bo...@aungate.com>
To: "'Struts Users Mailing List'" <us...@struts.apache.org>
Sent: Wednesday, May 25, 2005 1:20 PM
Subject: JSTL fmt:message with modules
> Hello, just trying out JSTL on a new app I'm writing as I thought
> it was about time I used it. However, I'm having a bit of trouble
> with the <fmt:message /> tag as I don't know how to specify the
> correct bundle to use.
>
> I'm using modules and tiles, so each module has it's own resource
> bundle, but they share the tiles templates. I'm trying to pass a
> page title with a tiles definition and have it pulled from the
> resource bundle and displayed. But I don't know how to tell the
> <fmt:message /> tag which bundle to use...?
>
> ...
> <title>
> <tiles:useAttribute id="title" name="title" scope="page" />
> <fmt:message key="${pageScope.title}" />
> </title>
> ...
>
> I've seen some web pages mention that you can put a context param
> in the web.xml:
>
> <context-param>
> <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
> <param-value>ApplicationResources</param-value>
> </context-param>
>
> But Shirley this wont work for modules...? Can anyone shed some
> light on how I get this to work...?
>
> Thanks,
>
> --
> Bob Arnott
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org