2

I have an f:loadBundle that loads a properties file from my classpath.

<f:loadBundle basename="com.xxx.ui.messages" var="msg" />

Later on, I'm attempting to use a message from the resource bundle with the following syntax:

<h:outputText value="test message: #{msg.does_not_exist} --"/>

It used to be that JSF would print out a "NOT FOUND" message, but now it's throwing an exception. Did the specification change or is this the correct behavior?

I'm using Mojarra 2.1.9 with JUEL 2.2.4 as a EL resolver. Here's the stack trace:

javax.el.PropertyNotFoundException: /WEB-INF/xxx.xhtml @10,70 value="test message: #{msg.does_not_exist} --": Property 'does_not_exist' not found on type java.util.PropertyResourceBundle
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)

EDIT: The correct behavior can be verified here: http://javaserverfaces.java.net/nonav/docs/2.0/vdldocs/facelets/f/loadBundle.html

(Which says the literal string ???KEY??? is returned from the Map, where KEY is the key being looked up in the Map, instead of a MissingResourceException being thrown)

EDIT: Same problem even after removing JUEL

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84
  • Were you using a different JSF implementation before? "Return garbage" is always dumb behaviour, I doubt that's what's specified. – millimoose Jun 14 '12 at 19:14
  • I'm fairly certain it's the correct behavior... for better or worse. See here: http://stackoverflow.com/questions/6451215/jsf-how-to-remove-the-surrounding-if-message-not-found-in-messagebundle – Jonathan S. Fisher Jun 14 '12 at 19:16
  • Verified that ??? does_not_exist ?? should be returned according to the docs here: http://javaserverfaces.java.net/nonav/docs/2.0/vdldocs/facelets/f/loadBundle.html – Jonathan S. Fisher Jun 14 '12 at 19:21
  • Ah. I thought you meant the string `NOT FOUND` exactly, not a placeholder value. – millimoose Jun 14 '12 at 20:15
  • This really seems like a bug in the JSF implementation then, the behaviour isn't even close to the spec. (A `PropertyResourceBundle` isn't a `Map` for starters.) – millimoose Jun 14 '12 at 20:18
  • I removed JUEL and used the default implementation (from tomcat). Same problem... – Jonathan S. Fisher Jun 14 '12 at 21:01

1 Answers1

3

So the answer is actually staring you in the face... props to @millimoose for getting me started down the right path.

Notice the specification says this:

the literal string ???KEY??? is returned from the Map, where KEY is the key being looked up in the Map, instead of a MissingResourceException being thrown.

But my stack trace says this:

javax.el.PropertyNotFoundException: /WEB-INF/xxx.xhtml @10,70 value="test message: #{msg.does_not_exist} --": Property 'does_not_exist' not found on type java.util.PropertyResourceBundle

Ahah, a possible bug!

Knowing that this class would be pulled from tomcat/lib, I browsed out to their source and javadoc here. Notice the throws declaration on "getValue()"?

That's in pretty stark contrast to the specification here.

So I removed el-api from tomcat/lib and replaced it with the spec jar (here) and problem solved!

Why Tomcat is so different from the specification is beyond me... those crazy Apache guys.

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84