2

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

2 Answers2

1

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'}"
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

It's usually a plain Resourcebundle object, so you can use its method:

<h:panelGroup rendered="#{res.containsKey('myKey')}">...
Speedstone
  • 383
  • 3
  • 5
  • Note that EL 2.2 wasn't commonly available at the date this question was asked. Before EL 2.2 was introduced, this line would throw an [EL syntax error](http://stackoverflow.com/questions/5273729/how-to-call-a-method-with-a-parameter-in-jsf). – BalusC Sep 21 '16 at 14:20