4

I would like to render a footer (with a specific content) if the datatable content is empty.

I found this How do I conditionally render an <f:facet>? but that doesnt really solve my problem, as it only renderes the footer if the message isnt empty.

 <f:facet name="footer">
      <h:outputText value="List is empty" rendered="#{empty list}" />
 </f:facet>

That does work if the list is empty, but if it isnt empty, this renderes an empty row as a footer...

Any other workaround? Thank you for your help! I'm using MyFaces 2.0.13.

Community
  • 1
  • 1
user1323246
  • 433
  • 2
  • 6
  • 23

2 Answers2

1

As far as I know there is no easy way to do this in JSF 1.2.

But you can use this workaround:

Create a css class with display: none:

.hidden { display: none; }

In your dataTable, specify the footerClass attribute as follows:

<h:dataTable footerClass="#{hideFooterCondition ? 'hidden' : ''}">

This way you are able to easily keep the footer hidden when it should be.

Additionally, if you want to reduce the data sent to the browser in the case the footer should not be present, you can use the same condition in the rendered attribute of facet's contents:

<f:facet name="footer">
    <rich:datascroller for="myDataTable" rendered="#{not hideFooterCondition}" />
</f:facet>    
Yuri Ghensev
  • 2,507
  • 4
  • 28
  • 45
  • Note that OP's concrete problem concerns specifically MyFaces `` (and that I've confirmed that OP's code works fine in Mojarra). – BalusC Nov 08 '12 at 12:05
-1

You could use a hpanel instead of a facet to control this. I am using this technique quite a bit in a few JSF applications I work on. Using conditionals in the view is considered poor practice in JSF from what I have read. HTML:

<h:panelGroup rendered="#{isEmpty}">
  <h:outputText value="List is empty" />
</h:panelGroup>

Backer bean:

boolean isEmpty = false;
if (list.isEmpty()) {
  isEmpty = true;
}
Lipongo
  • 1,221
  • 8
  • 14
  • Tried that too, but somehow it does not render anything no matter if the list is empty or not :( – user1323246 Sep 06 '12 at 15:16
  • The variable being checked from the backer bean should be a boolean that is set to true if the list is empty and false of the list contains values. – Lipongo Sep 06 '12 at 15:24
  • This "answer" makes no sense. – BalusC Sep 06 '12 at 15:36
  • @BalusC I edited the answer to include the backer bean, might help the answer make sense. Realized it needed more info after the prior comment. – Lipongo Sep 06 '12 at 15:47
  • Wrapping in a parent component and moving `rendered` attribute to it makes absolutely no difference in OP's particular problem. – BalusC Sep 06 '12 at 15:52