Just a quick question for you guys.
I have a resource key that is stored as a string in a managed bean and I’d like to get it to resolve to the value in a particular mapped Resource Bundle.
Here is what I started with:
<h:outputText value="#{msgs[bean.someVal]}"/>
I immediatly noticed that when someVal was null I would get the following exception:
javax.el.PropertyNotFoundException: /webpage.xhtml at line 118 and column 188 value="#{msgs[bean.someVal]}": Property '' not found on type java.util.PropertyResourceBundle
So I tried to set up a ternary like this:
<h:outputText value="#{bean.someVal == null ? '' : msgs[bean.someVal]}"/>
But I got the same error only quoting the new value.
I’m running JSF2.0 (Apache) on Tomcat6.
Anyone got any ideas? I’m pretty stumped on this one..
Let me know if you need more info, I hope this is enough to go on.. I’m thinking this is just something dumb that I’m doing 😉
You’ve there an empty string. An empty string is not the same as
null.Use the
emptycheck instead. It will check if the value is notnulland if it is not an empty string.An alternative, by the way, is to provide a custom
ResourceBundleimplementation on#{msgs}which doesn’t throw the exception, but instead returnsnullor an emptyStringonhandleGetObject()method.