You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bhaarat Sharma <bh...@gmail.com> on 2010/01/27 18:43:13 UTC

Any way to load resources in java.util.ResourceBundle

We have seen situations where sometimes the global resource bundles are lost
intermittently for some sessions.  We are in a clustered/shared environment
where multiple apps are deployed onto a GlassFishV2 server. Multiple apps
share the struts2 core jars.

We have some pages where we have written a custom Resource loader and
everything looks fine on these pages. Problem is on pages that utilize
<s:text name="my.label.name"/>. Our properties files reside globally in
WEB-INF/lib

Our custom resource loader works as follows in a JSP

<%CustomMessageResrouce cusResource = new
CustomMessageResource("Resource")%>
<%= cusResource.getMessage("my.label.name")%>

Java code for it looks like:
import java.util.ResourceBundle;
ResourceBundle resource = ResourceBundle.getBundle(baseName);


So we know that loading properties into resourcebundles and using them as
shown above works.

My question is..can we do the same for struts2. Can we forcefully load the
resourcebundles inside java.util.ResourceBundle and then have them be used
in <s:text> tag?

Re: Any way to load resources in java.util.ResourceBundle

Posted by roman danilin <ro...@mail.ru>.
Struts2 used com.opensymphony.xwork2.util.LocalizedTextUtil class for
managing Resource Bundles.

Maybe this scenario will help you:
- Create custom ServletContextListener for your webapp;
- Override contextInitialized method like this (change bundle name):

public void contextInitialized(ServletContextEvent event) {
    ResourceBundle bundle = ResourceBundle.getBundle("my-own-bundle");
   
LocalizedTextUtil.setDelegatedClassLoader(bundle.getClass().getClassLoader());
    LocalizedTextUtil.addDefaultResourceBundle("my-own-bundle");
}


omnipresent wrote:
> 
> no help on this one?
> 
> On Wed, Jan 27, 2010 at 12:43 PM, Bhaarat Sharma
> <bh...@gmail.com>wrote:
> 
>> We have seen situations where sometimes the global resource bundles are
>> lost intermittently for some sessions.  We are in a clustered/shared
>> environment where multiple apps are deployed onto a GlassFishV2 server.
>> Multiple apps share the struts2 core jars.
>>
>> We have some pages where we have written a custom Resource loader and
>> everything looks fine on these pages. Problem is on pages that utilize
>> <s:text name="my.label.name"/>. Our properties files reside globally in
>> WEB-INF/lib
>>
>> Our custom resource loader works as follows in a JSP
>>
>> <%CustomMessageResrouce cusResource = new
>> CustomMessageResource("Resource")%>
>> <%= cusResource.getMessage("my.label.name")%>
>>
>> Java code for it looks like:
>> import java.util.ResourceBundle;
>> ResourceBundle resource = ResourceBundle.getBundle(baseName);
>>
>>
>> So we know that loading properties into resourcebundles and using them as
>> shown above works.
>>
>> My question is..can we do the same for struts2. Can we forcefully load
>> the
>> resourcebundles inside java.util.ResourceBundle and then have them be
>> used
>> in <s:text> tag?
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Any-way-to-load-resources-in-java.util.ResourceBundle-tp27343882p27642648.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Any way to load resources in java.util.ResourceBundle

Posted by Bhaarat Sharma <bh...@gmail.com>.
no help on this one?

On Wed, Jan 27, 2010 at 12:43 PM, Bhaarat Sharma <bh...@gmail.com>wrote:

> We have seen situations where sometimes the global resource bundles are
> lost intermittently for some sessions.  We are in a clustered/shared
> environment where multiple apps are deployed onto a GlassFishV2 server.
> Multiple apps share the struts2 core jars.
>
> We have some pages where we have written a custom Resource loader and
> everything looks fine on these pages. Problem is on pages that utilize
> <s:text name="my.label.name"/>. Our properties files reside globally in
> WEB-INF/lib
>
> Our custom resource loader works as follows in a JSP
>
> <%CustomMessageResrouce cusResource = new
> CustomMessageResource("Resource")%>
> <%= cusResource.getMessage("my.label.name")%>
>
> Java code for it looks like:
> import java.util.ResourceBundle;
> ResourceBundle resource = ResourceBundle.getBundle(baseName);
>
>
> So we know that loading properties into resourcebundles and using them as
> shown above works.
>
> My question is..can we do the same for struts2. Can we forcefully load the
> resourcebundles inside java.util.ResourceBundle and then have them be used
> in <s:text> tag?
>
>