2
votes

I have a simple Primefaces Datatable with a SummaryRow. The values of this SummaryRow are calculated in the ManagedBean and available in simple BigDecimal variables. The DataTable is ordered by a String field.

Somehow, the DataTable is being displayed with the summaryRow in every row, and not in the last row.

I've searched for this but didn't find anything about.

I'm using Primefaces 5.3 with JSF 2.2.

The table: (https://drive.google.com/file/d/0Bw9aJmydXWmvdU8yTUkyYnp0Ums/view)

The XHTML:

<p:dataTable 
id="rgmStoricoContrattiSogettoCapogruppoDataTable" 
value="#{storicoSoggettoProdottoBean.sogegettoProdottoList}" 
var="soggetto"
rendered="#{storicoSoggettoProdottoBean.isNdgMemberOfGroup()}"
styleClass="common_datagrid"
emptyMessage="Nessun valore presente"
sortBy="#{soggetto.denominazione}" >

<p:column headerText="Soggetto">
    <p:commandLink 
        value="#{soggetto.denominazione} #{soggetto.ndg} - #{soggetto.ndgCapogruppo}" 
        actionListener="#{storicoSoggettoProdottoBean.redirectSoggetoProdotto(request.contextPath, soggetto)}"
        immediate="true"
        process="@this" 
        style="font-size: 11px !important;" />
</p:column>

<p:column headerText="Rating And./Cerved" width="67" style="text-align: center">
    <h:outputText value="#{soggetto.rating} / #{soggetto.ratingCerved}" />
</p:column>

<p:column headerText="Perfez. storico" width="60" style="text-align: right">
    <h:outputText value="#{soggetto.perfezionato}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column headerText="Accord." width="60" style="text-align: right">
    <h:outputText value="#{soggetto.accordato}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column headerText="Utilizz." width="60" style="text-align: right">
    <h:outputText value="#{soggetto.utilizzato}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column headerText="Sconfino" width="60" style="text-align: right">
    <h:outputText value="#{soggetto.sconfino}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column headerText="In proposta" width="60" style="text-align: right">
    <h:outputText value="#{soggetto.inProposta}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column headerText="Garanzie bancarie" width="60" style="text-align: right">
    <h:outputText value="#{soggetto.garanzieBancarie}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column headerText="Rischio indiretto vs gruppo" width="87" style="text-align: center;">
    <h:outputText rendered="#{soggetto.rischioIndirettoVsGruppo == true}" value="SÍ" style="color: green; font-weight: bold;" />
</p:column>

<p:column headerText="Rischio indiretto vs terzi" width="60" style="text-align: right">
    <h:outputText value="#{soggetto.rischioIndirettoVsTerzi}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column headerText="Rischio pond." width="60" style="text-align: right">
    <h:outputText value="#{soggetto.rischioPonderato}">
        <f:convertNumber type="currency" currencySymbol="€"/>
    </h:outputText>
</p:column>

<p:column width="25">
    <p:commandButton 
        action="#{storicoSoggettoProdottoBean.redirectToStoricoPlafond(request.contextPath, soggetto)}"
        immediate="true"
        process="@this"
        icon="fa fa-file-text-o" 
        styleClass="imageButton" 
        style="height: 12px;" />
</p:column>

<p:summaryRow>
    <p:column styleClass="totaleRowColor" style="text-align: right;">
        <h:outputText value="Totale:" style="font-weight: bold; text-transform: uppercase;" />
    </p:column>

    <p:column styleClass="totaleRowColor" width="67" />

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.perfezionatoSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.accordatoSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.utilizzatoSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.sconfinoSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.inPropostaSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.garanzieBancarieSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" width="87" />

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.rischioIndirettoVsTerziSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" style="text-align: right;" width="60">
        <h:outputText value="#{storicoSoggettoProdottoBean.rischioPonderatoSoggettoSum}">
            <f:convertNumber type="currency" currencySymbol="€"/>
        </h:outputText>
    </p:column>

    <p:column styleClass="totaleRowColor" width="25" />
</p:summaryRow>

4

4 Answers

4
votes

As noted in this question, you have to provide the sortBy attribute on the p:dataTable tag for the summary row to work (as you did in your code snippet). Primefaces uses the expression in the sortBy tag to group the table entries and then provide a summary row for each group.

To get only one group, I tried this:

<p:dataTable sortBy="#{1}" ...>

Works fine for me, I get just one summary row with my grand total now.

1
votes

Not sure if colspan attribute on column is required for expected result...?

Check the showcase of Primefaces for a sample if you didn't know: http://www.primefaces.org/showcase/ui/data/datatable/summaryRow.xhtml

1
votes

The summary row uses the sortBy expression, So if you use a sortBy that is say a unique ID, then Primefaces is always going to provide a summary row for every row in the table. Using a constant for sortBy like Ginkobonsai suggests sortBy="#{1}" is a good idea, You could alternatively use a constant field in the POJO.

0
votes

You can use a sortby value of some data that is shared by all of the rows.

Eg if you are using var soggetto

then you can have a field on that class that is equal across all objects.

Eg soggetto.dummysortby

in the class getDummySortBy returns 1.