Is there any way to prevent an h:datatable from creating an empty row when the backing value is empty? More specifically: I have a collection of data to be displayed in 3 columns in an h:dataTable with column headers. The thead always needs to be displayed, regardless of if there are elements in the list. This works fine, but when no elements are in the list, a single, empty row/cell is created in the tbody. Is there a way to prevent this?
Thanks!
Sample method from backing bean. For testing i've tried returning both null or an empty list. Same result for both.
public List<LocationsDecorator> getLocations() {
return null;
}
JSF fragment:
<h:dataTable styleClass="locations" id="locations1"
var="nearestLoc" value="#{confirmationBean.locations}">
<h:column>
<!-- column header -->
<f:facet name="header">Address</f:facet>
<!-- row record -->
#{nearestLoc.adddress}
</h:column>
<h:column>
<!-- column header -->
<f:facet name="header">Distance</f:facet>
<!-- row record -->
#{nearestLoc.distance}
</h:column>
<h:column>
<!-- column header -->
<f:facet name="header">Hours of Operation</f:facet>
<!-- row record -->
<h:dataTable styleClass="locations" var="data"
value="#{nearestLoc.hoursOfOperation}">
<h:column>
#{data}
</h:column>
</h:dataTable>
</h:column>
</h:dataTable>
Resulting HTML(The "<tr><td></td></tr>
" in the tbody is the problem):
<table id="contact:locations1" class="locations">
<thead>
<tr>
<th scope="col">Address</th>
<th scope="col">Distance</th>
<th scope="col">Hours of Operation</th>
</tr>
</thead>
<tbody>
<tr><td></td></tr></tbody>
</table>
Specify a separate style for an empty table. E.g.
table.empty tbody td {
border: 0;
}
And add it conditionally.
<h:dataTable ... styleClass="locations #{empty component.value ? 'empty' : ''}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With