Empty h:dataTable in JSF renders empty row with invalid number of columns?

Viewed 1996

I have the following JSF code which renders a table from a Bean which might be empty

<h:dataTable value="#{recController.currentRecList}" var="rec" styleClass="display" id="rec">
   <h:column>
     <f:facet name="header">
          <h:outputText value="#{msg['rec.name']}"/>
     </f:facet>
     #{rec.name}
   </h:column>
   <h:column>
     <f:facet name="header">
        <h:outputText value="#{msg['rec.notes']}"/>
     </f:facet>
     #{rec.notes}
  </h:column>
</h:dataTable>

problem is the above code renders the following HTML:

<tbody><tr><td></td></tr></tbody>

The above is wrong because it should render:

<tbody><tr><td></td><td></td></tr></tbody>

where the number of columns is two and not one! but even better it should render just:

<tbody></tbody>

So that DataTables js script recognizes there's no rows and shows a nice "Empty table".
Currently DataTables js script returns an error:

DataTables warning: table id=rec - Requested unknown parameter '1' for row 0. 
For more information about this error, please see http://datatables.net/tn/4

of course because it sees a row but with an incorrect number of columns.

warning datatables

Now using Primefaces p:dataTable produces even more boilerplate html code because the table is buried inside several div's and when an empty result is returned it produces a:

<tr class="ui-widget-content ui-datatable-empty-message">
<td class=" " colspan="4">No records found.</td>
</tr>

So again DataTables js (http://datatables.net/) finds a wrong number of columns. Is there a way to tell primefaces what html code to output when no result is found?

1 Answers
Related