How can I check if a Resource Bundle contains a specific key in a JSF page
I have a JSF page which has a bundle loaded. However I need to dynamiclly build a key to access the property. What I need to do is check that the property exists so I can decide whether to render the or not.
I have tried checking if the value is empty but it always renders the output.
Thanks
You can write a custom JSTL / Facelets function that takes two arguments - the bundle and the key, and verifies whether the key is contained. Something like:
value="#{cust:containsKey(msg, key) ? msg[key] : 'default'}"
It's usually a plain Resourcebundle object, so you can use its method:
<h:panelGroup rendered="#{res.containsKey('myKey')}">...
精彩评论