This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
I guess I could cook up something if I was using scriptlets, but how do I do this using JSTL?

Author and ninkuma
Posts: 66424
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The Blue Daisy",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Forum Bartender
Saurabh Pande
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK , name changed.

BTW, continuing with the topic at hand, I found some info at:

but the most important question, how to have one resource bundle handle all locales is still unanswered...
Posts: 1843
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write a generic DBResource class which takes a Locale in its constructor, and retrieves the appropriate values from the database.

The problem is passing this resource bundle to JSTL.
You can't use the fmt:setBundle tag as that only lets you specify a basename, and then uses ResourceBundle.getBundle() to find the bundle.

ResourceBundle.getBundle() looks for a class/properties file named with the appropriate Locale. That would require at minimum one class for each locale you were supporting. The class could merely extend your generic one, and call it straight away, but the class must still be present.

I suppose it would be possible to define those classes at runtime, based on the Locales in the database. But that involves invoking the ClassLoader.defineClass() method, that takes a byte[] or the class defined according to the VM spec. Not trivial to do.

The other approach I can think of is to shortcircuit JSTL. Instead of using a fmt:setBundle tag to configure the bundle, write your own tag that does it. (Tag preferred to scriptlet code) You just have to know the inner workings of JSTL a little - refer to the specification.

All it has to do is create an object of type javax.servlet.jsp.jstl.fmt.LocalizationContext, and put it into an attribute called "javax.servlet.jsp.jstl.fmt.localizationContext"

I think that should work ;-)
Take a look at the JSTL specification section 8, specifically 8.11.3

Hope this helps,
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!