Is it possible to test for enum equality in JSF?
E.g. where stuff is an enum Stuff:
<h:outputText value="text" rendered="#{mrBean.stuff == mrsBean.stuff}"/>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is actually more EL related than Faces related. The construct as you posted is valid, but you should keep in mind that enum values are in EL 2.1 or older actually evaluated as
Stringvalues. IfString.valueOf(mrBean.getStuff())equalsString.valueOf(mrsBean.getStuff()), then your code example will render. In EL 2.2 or newer the same construct will work, but they are evaluated as true enums.Note that it indeed requires a getter method to return the enum value. Given the fact that enums are treated as
String, you can in essence also just do:In EL, you cannot access enum values directly like this:
This is only possible when you use Faces 2.3-introduced
<f:importConstants>tag:Or when you’re not on Faces 2.3 yet or when you don’t want to use
<f:metadata>, use the OmniFaces predecesor<o:importConstants>: