[jsf] How to use && in EL boolean expressions in Facelets?

I am having a little trouble figuring out how to do and's on EL expressions in Facelets. So basically I have:

<h:outputText id="Prompt"
    value="Fobar" 
    rendered="#{beanA.prompt == true && beanB.currentBase !=null}" />

But I keep getting:

Error Traced[line: 69] The entity name must immediately follow the '&' in the entity reference.

This question is related to jsf facelets el

The answer is


Facelets is a XML based view technology. The & is a special character in XML representing the start of an entity like &amp; which ends with the ; character. You'd need to either escape it, which is ugly:

rendered="#{beanA.prompt == true &amp;&amp; beanB.currentBase != null}"

or to use the and keyword instead, which is preferred as to readability and maintainability:

rendered="#{beanA.prompt == true and beanB.currentBase != null}"

See also:


Unrelated to the concrete problem, comparing booleans with booleans makes little sense when the expression expects a boolean outcome already. I'd get rid of == true:

rendered="#{beanA.prompt and beanB.currentBase != null}"

In addition to the answer of BalusC, use the following Java RegExp to replace && with and:

Search:  (#\{[^\}]*)(&&)([^\}]*\})
Replace: $1and$3

You have run this regular expression replacement multiple times to find all occurences in case you are using >2 literals in your EL expressions. Mind to replace the leading # by $ if your EL expression syntax differs.


Examples related to jsf

Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes Target Unreachable, identifier resolved to null in JSF 2.2 Execution order of events when pressing PrimeFaces p:commandButton selectOneMenu ajax events The entity name must immediately follow the '&' in the entity reference java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config Primefaces valueChangeListener or <p:ajax listener not firing for p:selectOneMenu How does the 'binding' attribute work in JSF? When and how should it be used?

Examples related to facelets

The entity name must immediately follow the '&' in the entity reference Opening XML page shows "This XML file does not appear to have any style information associated with it." How to remove border from specific PrimeFaces p:panelGrid? How to use && in EL boolean expressions in Facelets? How to include another XHTML in XHTML using JSF 2.0 Facelets? Error parsing XHTML: The content of elements must consist of well-formed character data or markup How do I insert non breaking space character &nbsp; in a JSF page? Get Request and Session Parameters and Attributes from JSF pages How to display my application's errors in JSF?

Examples related to el

Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable Adding external resources (CSS/JavaScript/images etc) in JSP How does EL empty operator work in JSF? javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean How to use && in EL boolean expressions in Facelets? How do I check two or more conditions in one <c:if>? The representation of if-elseif-else in EL using JSF Use JSTL forEach loop's varStatus as an ID What does this expression language ${pageContext.request.contextPath} exactly do in JSP EL? How to access at request attributes in JSP?