如果jsf数据表为空,如何显示消息? [英] How do I display a message if a jsf datatable is empty?

查看:92
本文介绍了如果jsf数据表为空,如何显示消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JSF1.2,如果我的数据表绑定没有返回任何行,我想显示一条消息。

Using JSF1.2, if my datatable binding returns no rows I want to display a message saying so.

我该怎么做?

对于额外的积分 - 如果它是完全隐藏表的话空?

And for extra points - how do I hide the table completly if it's empty?

谢谢。

推荐答案

利用呈现属性。它接受一个布尔表达式。您可以借助EL的 empty 关键字来评估表达式中的数据表值。如果它返回 false ,则不会呈现整个组件(及其子组件)。

Make use of the rendered attribute. It accepts a boolean expression. You can evaluate the datatable's value inside the expression with help of the EL's empty keyword. If it returns false, the whole component (and its children) won't be rendered.

<h:outputText value="Table is empty!" rendered="#{empty bean.list}" />

<h:dataTable value="#{bean.list}" rendered="#{not empty bean.list}">
    ...
</h:dataTable>

对于您感兴趣的案例,以下是如何利用EL权力的其他基本示例在呈现的属性中:

For the case you're interested, here are other basic examples how to make use of the EL powers inside the rendered attribute:

<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'}" />



参见:




  • Java EE 7教程 - 表达语言 - 运算符

  • See also:

    • Java EE 7 tutorial - Expression Language - Operators
    • 这篇关于如果jsf数据表为空,如何显示消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆