开发者

Is ResourceBundle fallback resolution broken in Resin3x?

开发者 https://www.devze.com 2022-12-21 14:57 出处:网络
Given the followin开发者_JAVA技巧g ResourceBundle properties files: messages.properties messages_en.properties

Given the followin开发者_JAVA技巧g 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>


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消