I'm trying to conditionally render a primefaces fieldset using
<p:fieldset legend="content" rendered="#{controller.object.list.contains('THREAD_PROTRUSION')}" >
where 'THREAD_PROTRUSION' is an enum. The fieldset was not rendering when I felt it should so I added these outputs to my page:
#{controller.object.list}<br/>
#{controller.object.list.contains('THREAD_PROTRUSION')}<br/>
and the following is displayed
[THREAD_PROTRUSION, ENGAGE_NUT]
false
Why is the value false
when 'THREAD_PROTRUSION' is in the list?
There is a little more to this. The list is set from checkboxes on another screen and are populated by loading an JSON input file. If I go back to the view with the checkboxes and cycle them (uncheck, then recheck) then go back to the view with my fieldset, I see
[THREAD_PROTRUSION, ENGAGE_NUT]
true
and of course now the fieldset is rendered
== MCV Example
view.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:o="http://omnifaces.org/ui" xmlns:p="http://primefaces.org/ui" xmlns:bjap="http://bjap.gdeb.com/facelets">
<h:body>
<li><b>Enum List </b> #{bean.myList}</li>
<li><b>bean.myList[0] </b>#{bean.myList[0]}</li>
<li><b>bean.myList[1] </b>#{bean.myList[1]}</li>
<li><b>bean.myList.contains('RED') </b>#{bean.myList.contains('RED')}</li>
<li><b>bean.myList[0] eq 'RED' </b>#{bean.myList[0] eq 'RED'}</li>
<li><b>bean.myList[1] eq 'RED' </b>#{bean.myList[1] eq 'RED'}</li>
</h:body>
</html>
Bean.java
@Named
public class Bean implements Serializable {
private static final long serialVersionUID = 1L;
public enum Color {
WHITE, BLACK, RED, YELLOW, BLUE
}
private List<Color> myList;
public Bean() {
myList = new ArrayList<>();
myList.add(Color.WHITE);
myList.add(Color.RED);
}
public List<Color> getMyList() {
return myList;
}
public void setMyList(List<Color> myList) {
this.myList = myList;
}
}
output
Enum List [WHITE, RED]
bean.myList[0] WHITE
bean.myList[1] RED
bean.myList.contains('RED') false <-Expected to be true???
bean.myList[0] eq 'RED' false
bean.myList[1] eq 'RED' true