I just wanted to demonstrate why we should not be using JSTL tags to a colleague but I got lost not sure why is every thing getting rendered.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
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:c="http://java.sun.com/jstl/core">
<h:outputLabel>#{dummyBean.pageBuild}</h:outputLabel>
<h:outputLabel>#{dummyBean.pageRerendered}</h:outputLabel>
<h:outputLabel>#{dummyBean.pageBuild and !dummyBean.pageRerendered}</h:outputLabel>
<h:outputLabel>#{dummyBean.pageBuild and dummyBean.pageRerendered}</h:outputLabel>
<c:if test="#{dummyBean.pageBuild and !dummyBean.pageRerendered}">
<h:outputLabel value="Section 1"></h:outputLabel>
</c:if>
<c:if test="#{dummyBean.pageBuild and dummyBean.pageRerendered}">
<h:outputLabel value="Section 2"></h:outputLabel>
</c:if>
</ui:composition>
Results are
true
false
true
false
Section 1
Section 2
I would have thought they would be
true
false
true
false
Section 1
The
test="true"andtest="false"will always evaluate as booleantrue, simply because it are valid and non-nullStringvalues.You likely meant to use
test="#{true}"andtest="#{false}"instead.Another problem is that the XML namespace for JSTL tags is wrong, you’re using the one of Facelets 1.x while you’re using JSF 2.x. It should be
As to using JSTL in JSF, check this answer: JSTL in JSF2 Facelets… makes sense?