如何使用&&在Facelets的EL布尔表达式中? [英] How to use && in EL boolean expressions in Facelets?
问题描述
我在弄清楚Facelets中EL表达式的处理方法和方法时遇到了一些麻烦. 所以基本上我有:
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}" />
但我不断得到:
已跟踪错误[行:69]实体名称必须紧跟在'&'之后 在实体参考中.
Error Traced[line: 69] The entity name must immediately follow the '&' in the entity reference.
推荐答案
Facelets是一种基于XML的视图技术. &
是XML中的特殊字符,表示像;
字符结尾.您需要逃避它,这很丑:
Facelets is a XML based view technology. The &
is a special character in XML representing the start of an entity like &
which ends with the ;
character. You'd need to either escape it, which is ugly:
rendered="#{beanA.prompt == true && beanB.currentBase != null}"
或改用and
关键字,这在可读性和可维护性方面是首选:
or to use the and
keyword instead, which is preferred as to readability and maintainability:
rendered="#{beanA.prompt == true and beanB.currentBase != null}"
另请参见:
- Java EE 6教程-EL中的运算符
- Java EE 6 tutorial - Operators in EL
See also:
无关与具体问题无关,当表达式已经期望布尔结果时,将布尔值与布尔值进行比较就没有多大意义了.我会摆脱== true
:
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}"
这篇关于如何使用&&在Facelets的EL布尔表达式中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!