[英]How do I display a message if a jsf datatable is empty?
Using JSF1.2, if my datatable binding returns no rows I want to display a message saying so. 使用JSF1.2,如果我的数据表绑定没有返回任何行,我想显示一条消息。
How do I do that? 我怎么做?
And for extra points - how do I hide the table completly if it's empty? 而对于额外的积分 - 如果它是空的,我如何完整地隐藏表?
Thanks. 谢谢。
Make use of the rendered
attribute. 使用rendered
属性。 It accepts a boolean expression. 它接受一个布尔表达式。 You can evaluate the datatable's value inside the expression with help of the EL's empty
keyword. 您可以借助EL的empty
关键字来评估表达式中数据表的值。 If it returns false
, the whole component (and its children) won't be rendered. 如果返回false
,则不会呈现整个组件(及其子组件)。
<h:outputText value="Table is empty!" rendered="#{empty bean.list}" />
<h:dataTable value="#{bean.list}" rendered="#{not empty bean.list}">
...
</h:dataTable>
For the case you're interested, here are other basic examples how to make use of the EL powers inside the rendered
attribute: 对于您感兴趣的情况,以下是如何在rendered
属性中使用EL功能的其他基本示例:
<h:someComponent rendered="#{bean.booleanValue}" />
<h:someComponent rendered="#{bean.intValue gt 10}" />
<h:someComponent rendered="#{bean.objectValue eq null}" />
<h:someComponent rendered="#{bean.stringValue ne 'someValue'}" />
<h:someComponent rendered="#{not empty bean.collectionValue}" />
<h:someComponent rendered="#{not bean.booleanValue and bean.intValue ne 0}" />
<h:someComponent rendered="#{bean.enumValue eq 'ONE' or bean.enumValue eq 'TWO'}" />
You can test this in several ways, for example by having a function in a bean that tests the list size: 您可以通过多种方式对此进行测试,例如通过在bean中测试列表大小的函数:
function boolean isEmpty() {
return myList.isEmpty();
}
then in the JSF pages : 然后在JSF页面中:
<h:outputText value="List is empty" rendered="#{myBean.empty}"/>
<h:datatable ... rendered="#{!myBean.empty}">
...
</h:datatable>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.