简体   繁体   English

使用RichFaces datascroller时更新JSF数据表中的按页总计的问题

[英]Problem in updating page wise total in JSF datatable when using RichFaces datascroller

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. 我正在JSF页面中创建一个数据表,该数据表显示每列的页脚以及列页面中的总值。

I am using Richfaces datascroller for paging. 我正在使用Richfaces datascroller进行分页。

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 当我单击richfaces datascroller中的下一页时,我需要使用该页面中列值的总数来更新页脚,这对我来说是个问题

I managed to create the code to calculate page wise total by following this discussion http://forums.sun.com/thread.jspa?threadID=5254959 通过遵循以下讨论,我设法创建了计算按页总计的代码: 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. 当我在datascroller中单击下一页时,将保留相同的值。
For example when the column total of the first page is 5 and the second page is 3. 例如,当第一页的列总数为5而第二页的列总数为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. 我设法正确显示5,当我单击下一页时,我需要将其更新为3,但5保持不变。

It appears that only datatable body gets updated when I click the next button in datascroller. 当我单击datascroller中的下一个按钮时,似乎只有datatable主体得到更新。 Is there a way in Richfaces or JSF that makes the footer to get updated on every clicks? Richfaces或JSF中是否有一种方法可以使页脚在每次点击时都得到更新? Or is there any other alternative apart from Richfaces datascroller which solves my problem? 还是除了Richfaces datascroller以外,还有其他解决我问题的方法吗?

My JSF code is 我的JSF代码是

<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 我的java代码是

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 提前致谢

After a painful search for a week, I found a4j:jsFunction solves the problem for me. 经过一个星期的痛苦搜索,我发现a4j:jsFunction为我解决了这个问题。 Is there any other solution better than this? 还有其他解决方案吗? I am eager to know about it. 我很想知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM