How to retrieve JSTL resource bundle from plain java

R

Ron de Waard

Hello,

Our web-app uses Struts and JSTL combined with XSLT processing. For
the latter we want to use the same resource bundle as within Struts
and JSTL (we're using the preferred fmt:message now). Using Struts it
was easy to obtain the resource bundle by using:
MessageResources msgs =
(MessageResources)context.getAttribute(org.apache.struts.action.Action.MESSAGES_KEY);
This is deprecated however, but it works; I now can use this resource
bundle to translate some keys I want to use in XSLT transformations
(and more).

I want to do the same by obtaining the resource bundle from JSTL but
after searching everywhere I can't find the solution. Yes, I can
retrieve a single translated key, but I want to parse the whole
resourcebundle to our report engine. This tool must also work without
running in a web environment, and then I provide it with a standard
Java resource bundle.

Can anyone give me a clue how to obtain the resource bundle (with
choosen locale) as a object which can be used in plain Java code? I
want to get rid of the bean:message calls in favor of the fmt:message
calls.

Thanks in advance,

Ron de Waard
The Netherlands
 
M

Murray

MessageResources msgs =
(MessageResources)context.getAttribute(org.apache.struts.action.Action.MESSA
GES_KEY);
This is deprecated however, but it works;

FYI, the un-deprecated version is
context.getAttribute(org.apache.struts.Globals.MESSAGES_KEY);
I want to do the same by obtaining the resource bundle from JSTL but
after searching everywhere I can't find the solution. Yes, I can
retrieve a single translated key, but I want to parse the whole
resourcebundle to our report engine. This tool must also work without
running in a web environment, and then I provide it with a standard
Java resource bundle.

Would this help? (sorry I'm not exactly sure what you're after)

LocalizationContext i18nContext = (LocalizationContext)
Config.get(context, Config.FMT_LOCALIZATION_CONTEXT);
ResourceBundle rb = i18nContext.getResourceBundle();
 
N

navalverma

PropertyResourceBundle.getBundle(String baseName, Locale locale,
ClassLoader loader) also works.

You can not pass parameters to retrieve customized messages as in
MessageResource.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top