Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

java - 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.

How do I do that?

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

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

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

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...