我想在我的网页上添加一个条件来检查检索到的值是否为null或其他:
XHTML
<div id="topbarMsg" class="topbar-msg">
<c:if value="#{Bean.loginCustomer}" test = EMPTY>
<h:outputFormat id="welId" value="#{msg['label.welcome']} ">
</h:outputFormat>
<c:if test = NOT EMPTY>
<h:outputFormat id="welId" value="#{msg['label.welcomeUser']} ">
<f:param id="paramOneId" value="First Name" />
</div>
java bean
private Customer loginCustomer;
public final Customer getLoginCustomer() {
return loginCustomer;
}
从上面的代码中,它会检查firstname是否为空,并从那里调用正确的标签在网页上打印,但似乎无效。任何人???
答案 0 :(得分:1)
试试这个,
<h:outputFormat id="welId" value="#{Bean.loginCustomer eq empty ? msg['label.welcome']} : msg['label.welcomeUser']} ">
答案 1 :(得分:1)
如果没有看到您的Customer
bean和您的实际消息,就无法给出确定的答案,但应该与此有点接近:
<div id="topbarMsg" class="topbar-msg">
<h:panelGroup id="welId">
<h:outputFormat rendered="#{empty Bean.loginCustomer}"
value="#{msg['label.welcome']}" />
<h:outputFormat rendered="#{not empty Bean.loginCustomer}"
value="#{msg['label.welcomeUser']} ">
<f:param value="{Bean.loginCustomer.firstName}" />
</h:outputFormat>
</h:panelGroup>
</div>