How can I use an OR condition in <c:if> in Facelets? I need to check for privlage if it is 3 or 2 or 5.
<c:if test="#{Privlage=='3'or '2' or '5'}" >
Just follow the same logic as in normal Java:
if (privilege.equals("3") || privilege.equals("2") || privilege.equals("5"))
Thus, so:
<c:if test="#{privilege == '3' || privilege == '2' || privilege == '5'}">
You can use eq instead of == and or instead of || in EL.
<c:if test="#{privilege eq '3' or privilege eq '2' or privilege eq '5'}">
If you're on EL 3.0, then you can make use of new ability to declare inline collections via the new #{[...]} syntax for lists and #{{...}} syntax for sets. So, the below Java equivalent:
List<String> privileges = Arrays.asList("3", "2", "5");
if (privileges.contains(privilege))
Can in EL 3.0 be done like:
<c:if test="#{['3','2','5'].contains(privilege)}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With