Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use && in EL boolean expressions in Facelets?

Tags:

jsf

el

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.

like image 289
Landister Avatar asked Dec 18 '11 15:12

Landister


People also ask

When should a semicolon be used examples?

A semicolon may be used between independent clauses joined by a connector, such as and, but, or, nor, etc., when one or more commas appear in the first clause. Example: When I finish here, and I will soon, I'll be glad to help you; and that is a promise I will keep.

How do you use a semicolon in a sentence?

Semicolons Separate Clauses Here's an example: I have a big test tomorrow; I can't go out tonight. The two clauses in that sentence are separated by a semicolon and could be sentences on their own if you put a period between them instead: I have a big test tomorrow.

What is a semicolon example?

When to Use a Semicolon. A semicolon (;) is a punctuation mark that has two main functions: Semicolons separate items in a complex list. For example, The Council is comprised of ten members: three from Sydney, Australia; four from Auckland, New Zealand; two from Suva, Fiji; and one from Honiara, Solomon Islands.


1 Answers

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:

  • Java EE 6 tutorial - Operators in EL

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}" 
like image 91
BalusC Avatar answered Sep 22 '22 17:09

BalusC