views:

107

answers:

2

Given the following ResourceBundle properties files:

  1. messages.properties
  2. messages_en.properties
  3. messages_es.properties
  4. messages_{some locale}.properties

Note: messages.properties contains all the messages for the default locale. messages_en.properties is really empty - it's just there for correctness. messages_en.properties will fall back to messages.properties!

And given the following config params in web.xml:

<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>messages</param-value>
</context-param>

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
    <param-value>en</param-value>
</context-param>

I would expect that if the chosen locale is 'es', and a resource is not translated in 'es', then it would fall back to 'en', and finally to 'messages.properties' (since messages_en.properties is empty).

This is how things work in Jetty. I've also tested this on WebSphere.

Resin Is the Problem

The problem is when I get to Resin (3.0.23). Fallback resolution does not work at all! In order to get an messages to display, I must do the following:

  1. Rename messages.properties to messages_en.properties (essentially, swap the contents of messages.properties and messages_en.properties)
  2. Make sure ever key in messages_en.properties is also defined in messages_{every other locale}.properties (even if the exact same).

If I don't do this, I get "???some.key???" in the JSPs.

Please help! This is perplexing.

-- LES

SOLUTION

Add following to pom.xml (if you're using maven)

...
<properties>
    <taglibs.version>1.1.2</taglibs.version>
</properties>
...

    <!--
        Resin ships with a crappy JSTL implementation that doesn't work with
        fallback locales for resource bundles correctly; we therefore include
        our own JSTL implementation in the WAR, and avoid this problem. This
        can be removed if the target container is not resin.
    -->
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>${taglibs.version}</version>
        <scope>compile</scope>
    </dependency>
+1  A: 

Just an idea, but you could try adding this context-param as well:

<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
    <param-value>en</param-value>
</context-param>

It's possible that Resin is using something like that as the 'fallback' locale.

elduff
+1  A: 

I don't do Resin, so don't pin me on it, but the symptoms make it sound like that it ships with a poorly baked JSTL implementation. Try for instance to override it with a more decent one in the webapp's /WEB-INF/lib. If Servlet 2.5, get jstl-1.2.jar, or if Servlet 2.4, get jstl.jar and standard.jar.

BalusC
i was actually contemplating this myself. if i can do it for just my app it could work out, since the application server hosts many unrelated web apps (and i couldn't change it globally - i know, /WEB-INF/lib is specific to just my app, but i don't know if resin lets you change jstl for one app).
LES2
Give it a try. The only other way would be bugreporting and/or upgrading Resin (which seems to be a waste of time as it isn't maintained anymore since 2 years), or to switch to a more decent and actively maintained servletcontainer.
BalusC