commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Jouravlev <jmi...@gmail.com>
Subject Re: [RESOURCES] Messages vs. regular properties
Date Fri, 02 Dec 2005 00:57:39 GMT
On 12/1/05, Craig McClanahan <craigmcc@apache.org> wrote:
> On 12/1/05, Michael Jouravlev <jmikus@gmail.com> wrote:
> > Umm... So you are saying that I should use Message(s) for both error
> > messages and regular localised strings. Makes sense. How about
> > Messages to implement List? I know it sucks to implement all List
> > methods, but JSTL calls get("bla") for lists if I use something like
> > ${list["bla"]} in my JSP page. I think it would really simplify
> > things, because now I have to write
> > <li><i>
> >   <%= ((Messages)session.getAttribute("MSGS")).getMessage("label.user") %>
> > </i></li>
> > which is OK, but too long. Or maybe you can suggest a better way to
> > display messages?
>
>
> Even with JSTL expressions, I think a Map would be more useful than a List.

(1) Messages implements Map
I made Messages implementing Map. Most methods are stubs throwing an
exception, but I think they should not be. Why Messages and Resources
do not implement a collection anyway?

I implemented Object Map::get(Object key) like this:

    public Object get(Object key) {
        if (key == null) return null;
        if (!(key instanceof String)) return null;
        return (getMessage(resources, (String) key));
    }

Works like a charm, now I am able to write stuff like this:
  msgs = Messages.getMessages("AppResources");
  session.setAttribute("MSGS", msgs);

  <html>
    <h3><c:out value='${MSGS["heading.login"]}'/></h3>
  </html>

where file \WEB-INF\classes\AppResources.properties contains:
  heading.login=Log In

(2) Messages and Locale
If I understand correctly, static method getMessages() does not
support locale. But creating resource factory is a huge deal. I would
like to have getMessages() supporting locale. Actually, I would like
Messages accepting locale as "current" and saving it for future use
until it is changed by a user.

On 12/1/05, Craig McClanahan <craigmcc@apache.org> wrote:
> On 12/1/05, Michael Jouravlev <jmikus@gmail.com> wrote:
> >
> > On 12/1/05, Craig McClanahan <craigmcc@apache.org> wrote:
> > > Even with JSTL expressions, I think a Map would be more useful than a
> > List.
> >
> > Yes, of course Map is better. Thanks for correction, Craig.
> >
> > Btw, seems like ResourcesFactoryBase which is used in Messages, caches
> > resources in memory. This makes things faster, but I prefer this to be
> > configurable, so we would not have the "reloadable resources" problem.
>
>
> You can deal with "reloadable resources" by either overriding the caching
> (what the JDBC resources factory should do), or implementing a side
> mechanism that watches for file changes and reloads the underlying resources
> on the fly.

What I was talking about is that instead of listening to file changes
not cache messages at all. I mean, if I read them from messages object
- get them from memory. If I create messages object or I create a
factory object - read them from file or whatever other source *every
time*.

> Note that, if you use the ResourceBundle implementation, the JDK is going to
> cache these things anyway, if if we don't here.

Are you saying that when I read from a bundle, JDK caches all content
of property file in memory and does not access file for consecutive
reads? Really? I have to verify that, but that would be very
inconvenient.

Michael.

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


Mime
View raw message