0

I have to put in summary many columns summarizing the results, and in jsf datatable i cant do it, someone know how can i do it? without use primefaces

im got this result

<h:dataTable id="tableResult" value="#{managedBean.dataModel}"
                                    var="obj" rows="15" layout="block" styleClass="table">
    <h:column>
            <f:facet name="header">Total abandonada</f:facet>
            <h:outputText value="#{obj.totalAbandon}">
            </h:outputText>
        </h:column>
        <h:column>
            <f:facet name="header">Total</f:facet>
            <h:outputText value="#{obj.total}" />

        </h:column>
        <h:column>
            <f:facet name="header"> Atendidas %</f:facet>
            <h:outputText value="#{obj.percentualAnswered}%" />
        </h:column>
        <h:column>
            <f:facet name="header">Abandonos %</f:facet>
            <h:outputText value="#{obj.percentualAbandon}%" />
        </h:column>
        <f:facet name="footer">#{obj.suumary}
        </f:facet>
</h:dataTable>

to got this result im using

<f:facet name="footer">Total : 2</f:facet>

but i want this result

<tr>
<td>Total : 2</td> 
<td>Total answered : 1</td>
<td>Total abandon : 1</td>
</tr>
</tfoot>

i have been tried use 2 footer facet and doesnt work

  • 3
    @fuggerjaki61: No not the complete datatable. Just a [mcve]. Often one column is already sufficient. – Kukeltje Apr 14 '20 at 15:00

1 Answers1

0

A plain JSF h:datatable does not have the notion of something like a summary per group of rows built in. So if this is what you want, you need to either switch to e.g. PrimeFaces or add the summary row to your model in the right place and be creative with the CSS for the rows and the content.

If you want a footer for the full datable, the footer facet is the right thing (a summary of the datatable). But in this footer you cannot use the variable you assigned in the var attribute, in your case obj Think of it, which obj should be used? The first? Second? Last? All (each)? So add a field to the managedBean that contains the 'summary' and display that.

<f:facet name="footer">#{manageBean.summary}</f:facet>

If summary is a list, you can iterate over it like mentioned in Iterate over nested List property inside h:datatable

The html you'll end up is

<tfoot>
   <tr> 
       <td>
          .... your content of the nested list
       </td>
   </tr>
</tfoot>

This contnt can be either a table, list, div's or whatever you want.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • if i put it -> #{manageBean.summary} im gonna have just one TD Total : 2 but i want many TD like Total : 2 Total answered : 1 Total abandon : 1 – Diego Guimarães Apr 15 '20 at 19:23
  • Than make sure your summary field returns a list and iterate over that in the footer facet like you would when outputting to sysout or whatever in a structured way. And in the output html optimise the looks with css. – Kukeltje Apr 16 '20 at 07:44