Primefaces dataTable具有多个行计数

时间:2016-11-12 15:34:46

标签: jsf primefaces datatable

下一个数据表是每个时期(月/年)传输和未传输的文件的报告。我需要在currentPageReportTemplate属性中包含多个行计数。总计数,传输文件数和未传输文件数。

<p:dataTable id="repFiles" var="rep" value="#{reportFilesBean.list}" filteredValue="#{reportFilesBean.listFiltered}"
         paginator="true" rows="20" sortMode="multiple" emptyMessage="Empty result"
         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
         currentPageReportTemplate="Total: {totalRecords} / Transferred: #{reportFilesBean.countTrans} / Not transferred: #{reportFilesBean.countNotTrans}"
         rowsPerPageTemplate="10,20,30,40,50,100" scrollable="true"  style="width: 100%;"  >

    <f:event type="org.primefaces.event.data.PostFilterEvent" listener="#{reportFilesBean.postFilter}" />

    <f:facet name="header">
        Files transfered
    </f:facet>

    <p:column sortBy="#{rep.period}" filterBy="#{rep.period}" filterMatchMode="contains">  
        <f:facet name="header">
            <h:outputText value="Period" />
        </f:facet>
        <h:outputText value="#{rep.period}" />
    </p:column>

    <p:column sortBy="#{rep.filename}" filterBy="#{rep.filename}" filterMatchMode="contains"> 
        <f:facet name="header">
            <h:outputText value="Filename" />
        </f:facet>
        <h:outputText value="#{rep.filename}" />
    </p:column>

    <p:column sortBy="#{rep.date}" filterBy="#{rep.date}" filterMatchMode="contains"> 
        <f:facet name="header">
            <h:outputText value="Date" />
        </f:facet>
        <h:outputText value="#{rep.date}" />
    </p:column>
</p:dataTable>
@ManagedBean
@ViewScoped
public class ReportFilesBean implements Serializable {

    private List<ReportFile> list;
    private List<ReportFile> listFiltered;

    private Long countTrans;
    private Long countNotTrans;

    public ReportFilesBean() {
        list = new ArrayList<ReportFile>();
        countTrans = 0L;
        countNotTrans = 0L;
    }

    public void generateReport(ActionEvent actionEvent) {
        Long[] c = {0L, 0L};
        list = dao.reportFile(c);
        countTrans = c[0];
        countNotTrans = c[1];
    }

    public void postFilter(ComponentSystemEvent e) {
        countTrans = 0L;
        countNotTrans = 0L;

        for (ReportFile r : listFiltered) {
            if (r.getFilename() != null){
                cantTrans++;
            } else {
                cantNoTrans++;
            }
        }
    }

    /* Getters and Setters */
}

在生成报告时,正确显示变量countTrans和countNotTrans。但是,在过滤时,它们保持最初加载的值。我调试postFilter方法并且计数成功但数据表没有更新。

请你帮忙,我已阅读,但我没有找到类似情况的例子。 提前谢谢。

0 个答案:

没有答案