Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

How to retrieve JSTL resource bundle from plain java

Thread view: 
Ron de Waard - 29 Mar 2005 13:02 GMT
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
Murray - 29 Mar 2005 14:40 GMT
> 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();
navalverma@yahoo.com - 29 Mar 2005 18:52 GMT
PropertyResourceBundle.getBundle(String baseName, Locale locale,
ClassLoader loader) also works.

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.