Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL setBundle Tag - how to reload a resource bundle dynamically  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have the following working example that load resource bundles using JSTL fmt Tag Library:

Header.jsp has this:
<fmt:setBundle var="link" basename="resources.LinkResources" scope="session" />

Phone.jsp has this:
... includes Header.jsp...
<fmt:message key="image.but_clickhere_on.gif.relative" bundle="${link}" />
... looks like this:

By default JSTL use the ResourceBundle java class to load the bundle. The issue with this example is the resource bundle "resources.LinkResources" is not reloaded when a change is made to the file.

I am attempting to resolve this issue of reloading resource bundles by doing the following:

1) in a Filter class set the 'link' attribute in the session so that every time a session starts the resource bundle is reloaded. Code is:

InputStream in = this.getClass().getClassLoader().getResourceAsStream("resources/");
PropertyResourceBundle lrb = new PropertyResourceBundle(in);
session.setAttribute("link", lrb);

2) remove from Header.jsp above the code:
<fmt:setBundle ...

3) leave Phone.jsp unchanged

I was expecting this to work. But the Phone.jsp page doesn't display. I thought the ${link} would find the attribute in session and use the 'lrb' resource bundle set up in the filter.

The error I see in the weblogic domain server log is:
I get the following error in the weblogic domain server log:
javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "bundle" with value "${link}": Attempt to coerce a value of type "java.util.PropertyResourceBundle" to type "javax.servlet.jsp.jstl.fmt.LocalizationContext" (null)
at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(
at org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(

Any suggestions would be appreciated as how to make this work or other approaches....Thanks in advance.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!