Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF: how do you add an empty row to a :dataTable?

Tags:

datatable

jsf

I have a data table like:

<h:dataTable id="box-score-away" value="#{individualAwayBoxScoreQuery.resultList}" var="_bssl">
  <f:facet name="header">
    <h:outputText value="Away Team" />
  </f:facet>
  <h:column>
    <f:facet name="header">
      <h:outputText value="Name" />
    </f:facet>
    <h:outputText value="#{_bssl.name}" />
    <f:facet name="footer">
      <h:outputText value="&#931;" styleClass="bold" />
    </f:facet>
  </h:column>
  ...
</h:dataTable>

When the result list has no elements, the table's tbody becomes empty. Firefox has problems with that and page rendering is really messed up.

How do I add a line to tbody when the result list is empty? (Note, it's not about the condition but rather the components to use and where to put them.)

The row is supposed to be a td with a colspan of 10. I tried a few things without success. Is f:verbatim the way to go?

like image 281
Kawu Avatar asked Dec 10 '25 03:12

Kawu


2 Answers

#{individualAwayBoxScoreQuery.resultList}

You can handle this in your model. Conditionally return a List containing a single empty bean (I guess a Map would do too). There are several ways to do this: in the back bean; an EL functions; etc.

If memory servers, MyFaces does this automatically to generate valid XHTML.

like image 56
McDowell Avatar answered Dec 13 '25 01:12

McDowell


I had similar problem and I ended up using dojo to add a <tr> to the table body.

For the example above it might look something like below:

dojo.addOnLoad(function(){

if(dojo.isMozilla) {
    var bodyElem = dojo.query(".yourTablesStyleClass tbody")[0];

    dojo.create("tr", null, bodyElem, "last");

}  });
like image 40
Issa Avatar answered Dec 13 '25 01:12

Issa