I'm not totally done with my implementation, so I can't vouch that it
will work 100% correctly, but here's what I'm trying:
1. Use Spring's ReloadableResourceBundleMessageSource and point its
baseName to the StripesResources file. You can do it this way (I think)
in applicationContext.xml:
<property name="basename" value="classpath:StripesResources" />
This assumes that you put the StripesResources file(s) in
WEB-INF/classes.
2. Implement Stripes' LocalizationBundleFactory. Override
getErrorMessageBundle and getFormFieldBundle to return an instance of
Spring's MessageSourceResourceBundle, created by using your
ReloadableResourceBundleMessageSource and the Locale passed into the
method.
3. Here's what I'm doing which some won't want to do. When you're
ready to reload the StripesResource file, place an updated copy of it at
a predetermined spot on your web server.
4. Write an ActionBean that you hit when you want to reload. In the
ActionBean, do this:
* Get the instance of your ReloadableResourceBundleMessageSource
from the Spring application context
* Set the basename to the URL of your StripesResources on the web
server, such as "http://www.yourcompany.com/resources/StripesResources".
Note that you did not add the .properties extension; The MessageSource
will do this for you, in addition to looking up the rile file based on
Locale (I think). If you're really sneaky you'll use something like
this to build the URL so it's always independent of your server
environment:
String url = request.getScheme() + "://" + request.getServerName() + ":"
+ request.getServerPort() + "/myapp/resources/StripesResources";
* After setting the basename, call the clearCache() method of the
MessageSource. This will cause it to reload itself.
And that should do it.
You follow the same basic approach if you wanted to use a database
instead but you'd have to figure out how to fill the MessageSource with
info from the database yourself.
If you have some luck with it, or have some improvement suggestions,
please let me know!!
-Ryan
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Scott
Archer
Sent: Thursday, May 15, 2008 3:17 PM
To: Stripes Users List
Subject: Re: [Stripes-users] Specifying ResourcesBundles in
<fmt:message> Tag
I'm interested in doing something similar. I'd like to store my
resources in a database table, or a .properties file outside of the
deployed .war file (in a configuration directory).
Has anyone had any luck doing that sort of thing?
On Thu, May 15, 2008 at 10:07 AM, Leonard Gestrin
<[EMAIL PROTECTED]> wrote:
> Hi Ryan
>
> I don't think specifying bundle inside fmt:message tag works at all.
> You can workaround this problem by doing something like this
>
>
>
> <fmt:bundle value= "${actionBean.resourceBundle}" > <fmt:message
> key="label.key.here" /></fmt:bundle>
>
> I don't remember exact spelling for fmt:bundle but it should be easy
> to look it up.
>
>
>
> The expected value for bundle is bundle name, which is a string - I
> your example you are passing implementation of resource bundle.
>
>
>
> Specifying bundle name helps to play with multiple bundles at the same
time.
> It looks like you have one bundle but you want JSTL to use Spring
> implementation to load it as oppose to default one. I don't know how
> to do it, but I am sure Spring's forum must have an example.
>
>
>
>
>
>
>
> ________________________________
>
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Asleson, Ryan
> Sent: Thursday, May 15, 2008 6:02 AM
> To: Stripes Users List
> Subject: [Stripes-users] Specifying ResourcesBundles in <fmt:message>
> Tag
>
>
>
>
>
> Hello,
>
>
>
> This question isn't necessarily Stripes specific, but with Stripes'
> good support for i18n I'll ask it anyways.
>
>
>
> I want to create a ResourceBundle system that can be reloaded at
> runtime, without having to redeploy the application with a new
> StripesResources file.
>
>
>
> To do this, I used the Spring MessageSourceResourceBundle (which
> extends
> ResourceBundle) which is backed by a Spring
> ReloadableResourceBundleMessageSource (which provides the
> functionality for the bundle to be reloaded at runtime). Next, I
> created a class that implements LocalizationBundleFactory and plugged
> it into Stripes as recommended; this class returns the instance of the
> MessageSourceResourceBundle.
>
>
>
> Now, in my JSP when I'm trying to insert localized text, I figured I'd
> use the JSTL <fmt:message> tag. Since I'm not using the "basic"
> StripesResources bundle, I thought I'd have to provide the
> ResourceBundle to the <fmt:message> tag using the "bundle" attribute.
> I created an accessor on my ActionBean for the
> MessageSourceResourceBundle and tried to use this
> tag:
>
>
>
> <fmt:message bundle="${actionBean.resourceBundle}"
> key="label.key.here" />
>
>
>
> But adding the "bundle" attribute causes this failure to occur:
>
>
>
> org.apache.jasper.JasperException: java.lang.IllegalArgumentException:
> Cannot convert
> [EMAIL PROTECTED]
> 2 of type class
> org.springframework.context.support.MessageSourceResourceBundle
> to class javax.servlet.jsp.jstl.fmt.LocalizationContext
>
>
>
> All the documentation I've read says that the "bundle" attribute of
> <fmt:message> takes a ResourceBundle, but doing so causes a failure.
> As a sanity check I also had actionBean.resourceBundle return a
regular ol'
> ResourceBundle but it failed with a similar message.
>
> Can anybody shed some light on why I can't provide a ResourceBundle to
> the <fmt:message> tag? Or how I should go about displaying localized
> text on the JSP?
>
> Thank you!!
>
> -Ryan
>
>
>
>
>
>
>
> This e-mail message is being sent solely for use by the intended
> recipient(s) and may contain confidential information. Any
> unauthorized review, use, disclosure or distribution is prohibited. If
> you are not the intended recipient, please contact the sender by phone
> or reply by e-mail, delete the original message and destroy all
copies. Thank you.
>
> ----------------------------------------------------------------------
> --- This SF.net email is sponsored by: Microsoft Defy all challenges.
> Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
------------------------------------------------------------------------
-
This SF.net email is sponsored by: Microsoft Defy all challenges.
Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
This e-mail message is being sent solely for use by the intended recipient(s)
and may contain confidential information. Any unauthorized review, use,
disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by phone or reply by e-mail, delete the
original message and destroy all copies. Thank you.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users