Forums Register Login

Database Resource Bundles and JSTL

+Pie Number of slices to send: Send
Hi.

Anyone know how I can extend ResourceBundle so that I can return key:value pairs picked up from a Database?

I want to be able to do this from JSTL.

Is there an implemention of this (DBResourceBundle?) already available somewhere? ListResourceBundle is just not flexible enough for me. Also, I dont want to have to create a new class for every language. Can't I just pass the Local to one class and have it pick up the releated info from a database?

I guess I could cook up something if I was using scriptlets, but how do I do this using JSTL?

TIA
+Pie Number of slices to send: Send
"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.

Thanks!
bear
Forum Bartender
+Pie Number of slices to send: Send
OK , name changed.

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

http://forum.java.sun.com/thread.jspa?threadID=543805&tstart=120

but the most important question, how to have one resource bundle handle all locales is still unanswered...
+Pie Number of slices to send: Send
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,
evnafets
Everybody's invited. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2309 times.
Similar Threads
Struts Plugin - Getting webapplicationcontext or service factory in struts plug-in class
How to save values in a database in JSTL?
database connection using jstl
beans in JSTL ?
struts Action for asynchronous HTTP processing
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:18:48.