如何在 Facelets 使用 & & EL 布尔表达式?

我有一点困难,搞清楚如何做和的在 Facelets EL 表达式。 所以基本上我有:

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

但我一直在想:

错误跟踪[第69行]实体名称必须紧跟在“ &”之后 在实体引用中。

115850 次浏览

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.