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! See I guess I could cook up something if I was using scriptlets, but how do I do this using JSTL?
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