I'm working in a legacy JSF web app, and my h:dataTable element is giving me trouble. Normally, it displays exactly how I want it - a header and several rows, all with proper padding and margins and everything.
However, if I try to display a table with zero rows (which is a valid use case for me), JSF still renders one row, albeit empty of contents.
Here's the source code for this h:dataTable:
<h:dataTable styleClass="table" value="#{backingBean.emptyList}" var="result">
<h:column>
<f:facet name="header">First Column</f:facet>
<h:outputText value="#{result}"/>
</h:column>
<h:column>
<f:facet name="header">Second Column</f:facet>
<h:outputText value="#{result}"/>
</h:column>
<h:column>
<f:facet name="header">Third Column</f:facet>
<h:outputText value="#{result}"/>
</h:column>
</h:dataTable>
Here's what's being rendered by the browser:
<table class="table">
<thead>
<tr>
<th scope="col">First Column</th>
<th scope="col">Second Column</th>
<th scope="col">Third Column</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Here are the methods in the backing bean that give me my result list:
public List<String> getEmptyList() { // incorrectly renders 1 empty row
return Collections.emptyList();
}
public List<String> getThreeRows() { // correctly renders 3 rows
return Arrays.asList(new String[] {"row1", "row2", "row3"});
}
Why is JSF rendering this empty row? I would have expected the <tbody>
to just be empty. Is this the correct behavior for JSF? or do I have something misconfigured?
Please advise,
-August
<h:dataTable><h:column/></h:dataTable>
has a body with a row with a cell:<table> <tbody> <tr><td></td></tr></tbody> </table>
– Selaron