views:

181

answers:

1

I am creating a datatable in my JSF page which shows the footer for every column with the total of values in the column page wise.

I am using Richfaces datascroller for paging.

When I click next page in richfaces datascroller I need to update my footer with the total of column values in that page, which now a problem for me

I managed to create the code to calculate page wise total by following this discussion http://forums.sun.com/thread.jspa?threadID=5254959

When the page with the datatable loads I managed to see the total of column correctly in the footer. When I click next page in datascroller the same value remains.
For example when the column total of the first page is 5 and the second page is 3.

I managed to show 5 correctly, when I click the next page I need it to be updated to 3, but 5 remains unchanged.

It appears that only datatable body gets updated when I click the next button in datascroller. Is there a way in Richfaces or JSF that makes the footer to get updated on every clicks? Or is there any other alternative apart from Richfaces datascroller which solves my problem?

My JSF code is

<h:dataTable id="summary" binding="#{outboundCall.summaryTable}">

                                </h:dataTable>
                                <rich:datascroller reRender="summary" for="summary" style="width:623px;font-family : Verdana;font-weight: bold;">

                                </rich:datascroller>

My java code is

public HtmlDataTable getSummaryTable() 
{
    summaryTable = new HtmlDataTable();
    summaryTable.setRowClasses("datatablecontent");
    summaryTable.setColumnClasses("datatablecontent");
    summaryTable.setHeaderClass("datatableheader");
    summaryTable.setFooterClass("datatablecontent");
    summaryTable.setVar("data");
    summaryTable.setRows(5);
    //summaryTable.setId("summaryTable");
    summaryTable.setValueExpression("value", createValueExpression("#{outboundCall.summaryReports}", List.class));
    summaryTable.setRendered(getDataTableRendered());

    HtmlColumn column1 = getColumnDetails("Dialled Date", "#{data.dialledDate}");
    HtmlOutputText footerText1 = new HtmlOutputText();
    footerText1.setValue("Total");        
    column1.setFooter(footerText1);
    summaryTable.getChildren().add(column1);

    if(getStatus().equalsIgnoreCase("success") || getStatus().equalsIgnoreCase("all"))
    {
        System.out.println("Before footer calculation");
        int subTotalPrice = 0;
        for (int i = summaryTable.getFirst(); 
                 i < summaryTable.getFirst() + summaryTable.getRows() && 
                 i < getSummaryReports().size(); i++) 
        {
            SummaryReportsForOutBoundCalls dataItem = getSummaryReports().get(i);
            String dataItemPrice = dataItem.getSuccessCount();
            subTotalPrice += Integer.parseInt(dataItemPrice);
            dataItem.setTotalCallsTotal(Integer.toString(subTotalPrice));
        }

        setFooterTotalToDisplay(Integer.toString(subTotalPrice));
        HtmlColumn column2 = getColumnDetails("Success", "#{data.successCount}");
        HtmlOutputText footerText2 = new HtmlOutputText();
        footerText2.setValue(subTotalPrice);
        column2.setFooter(footerText2);

        summaryTable.getChildren().add(column2);            
    }

    return summaryTable;
}

This is the code where I calculated page wise total

public List<SummaryReportsForOutBoundCalls> getSummaryReports() 
{
    int total = 0;

    //getSummaryTable();

    for (int i = summaryTable.getFirst(); 
     i < summaryTable.getFirst() + summaryTable.getRows() && 
     i < summaryReports.size(); i++) 
    {
        SummaryReportsForOutBoundCalls dataItem = summaryReports.get(i);
        String dataItemPrice = dataItem.getSuccessCount();
        total += Integer.parseInt(dataItemPrice);
        dataItem.setTotalCallsTotal(Integer.toString(total));

    }       
    scroller.setOncomplete("setValue('"+total+"')");
    scroller.setOnclick("setValue('"+total+"')");
    setFooterTotalToDisplay(Integer.toString(total));
    footerText2.setValue(total);

    return summaryReports;              
}

Please help me to solve this

Thanks in advance

A: 

After a painful search for a week, I found a4j:jsFunction solves the problem for me. Is there any other solution better than this? I am eager to know about it.

mvg