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.
2 个解决方案
#1
91
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.
使用呈现的属性。它接受一个布尔表达式。您可以借助EL的空关键字来评估表达式中数据表的值。如果返回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:
对于您感兴趣的情况,以下是如何在渲染属性中使用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'}" />
See also:
- Java EE 7 tutorial - Expression Language - Operators
Java EE 7教程 - 表达式语言 - 运算符
#2
2
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>
#1
91
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.
使用呈现的属性。它接受一个布尔表达式。您可以借助EL的空关键字来评估表达式中数据表的值。如果返回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:
对于您感兴趣的情况,以下是如何在渲染属性中使用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'}" />
See also:
- Java EE 7 tutorial - Expression Language - Operators
Java EE 7教程 - 表达式语言 - 运算符
#2
2
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>