JSF conditionally handles footer (jsf facet)

I want to make a footer (with specific content) if the contents of the datatable is empty.

I found this. How do I conditionally display <f: facet>? but it really doesnโ€™t help solve my problem as it only does the footer if the message is not empty.

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

This works if the list is empty, but if it is not empty, it creates an empty line in the form of a footer ...

Any other workaround? Thanks for the help! I am using MyFaces 2.0.13.

+4
source share
2 answers

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

But you can use this workaround:

Create a css class with display: none :

 .hidden { display: none; } 

In your data table, specify the footerClass attribute as follows:

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

This way you can easily hide the footer when it will be.

In addition, if you want to reduce the data sent to the browser if the footer should not be present, you can use the same condition in the rendered attribute for the contents of the face:

 <f:facet name="footer"> <rich:datascroller for="myDataTable" rendered="#{not hideFooterCondition}" /> </f:facet> 
0
source

You can use hpanel instead of a face to control it. I use this technique quite a bit in the several JSF applications that I am working on. Using conditional expressions in a view is considered bad practice in JSF from what I read. HTML:

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

Bean Bean:

 boolean isEmpty = false; if (list.isEmpty()) { isEmpty = true; } 
-1
source

Source: https://habr.com/ru/post/1432735/


All Articles