【问题标题】:How to check if objects are not empty如何检查对象是否为空
【发布时间】:2013-10-11 11:11:14
【问题描述】:
我正在尝试检查 JSF 1.2 视图中的对象是否为空。表达式为:
<h:panelGroup rendered="#{deuteBB.detallDeute.estatDomiciliacio ne empty and deuteBB.detallDeute.cccDomiciliacio ne empty}">
但是,这不起作用,&& 而不是 and。这是如何引起的,我该如何解决?
【问题讨论】:
标签:
jsf
el
jsf-1.2
is-empty
【解决方案1】:
在您的尝试中,您基本上是将其与名称为 empty 的变量进行比较,就像在“普通 Java”中一样:
if (!deuteBB.getDetallDeute().getEstatDomiciliacio().equals(empty) && !deuteBB.getDetallDeute().getCcccDomiciliacio().equals(empty))
因此这绝对是不对的。 EL 中正确的empty 运算符是前缀运算符,因此应该像#{not empty bean.property} 那样使用。
在您的特定情况下,应该这样做:
<h:panelGroup rendered="#{not empty deuteBB.detallDeute.estatDomiciliacio and not empty deuteBB.detallDeute.cccDomiciliacio}">