我正在使用事件过滤器重新计算某些列的总数,当过滤器运行新值在backingBean中计算正常但未在表中更新时。值为sumaTotal,sumaCUP和sumaCUC,并显示在每列的页脚。 这是代码:
<p:dataTable emptyMessage="No se encontraron elementos" widgetVar="tb1"
id="tablaFact" var="item" selection="#{listadoFacturasMB.selectedFactura}" selectionMode="single" paginator="true"
rows="20" rowKey="#{item.idFactura}" value="#{listadoFacturasMB.facturaUtilList}" filteredValue="#{listadoFacturasMB.filterFacturaUtilList}">
<p:ajax event="rowSelect" update=":frm1:growl :frm1:panelDetallesServicio" oncomplete="servDialog.show()" listener="#{listadoFacturasMB.createPDF}"/>
<p:ajax event="rowUnselect" update=":frm1:growl"/>
<p:ajax event="filter" listener="#{listadoFacturasMB.filterListener(filterEvent)}" update="tablaFact"/>
<f:facet name="header">
<h:outputText value="Listado de facturas"/>
<p:commandButton id="downloadLink" value="Recargar" icon="ui-icon-refresh" oncomplete="tb1.clearFilters()" update="tablaFact" actionListener="#{listadoFacturasMB.cargarFacturas}"/>
</f:facet>
<p:column style="width:10%" sortBy="#{item.noFactura}" filterBy="#{item.noFactura}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Nro"/>
</f:facet>
<h:outputText value="#{item.noFactura}"/>
</p:column>
<p:column style="width:10%" sortBy="#{item.idClientefk}" filterBy="#{item.idClientefk}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Cliente"/>
</f:facet>
<h:outputText value="#{item.idClientefk}"/>
</p:column>
<p:column style="width:10%" sortBy="#{item.idPropietariofk.area}" filterBy="#{item.idPropietariofk.area}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="UEB"/>
</f:facet>
<h:outputText value="#{item.idPropietariofk.area}"/>
</p:column>
<p:column style="width:10%" id="cff3">
<f:facet name="header">
<h:outputText value='Importe Total'/>
</f:facet>
<h:outputText value="#{item.importeTotal}"/>
<f:facet name="footer">
<h:outputText value="#{listadoFacturasMB.sumaTotal}"/>
</f:facet>
</p:column>
<p:column style="width:10%" id="cdd3">
<f:facet name="header">
<h:outputText value='Importe CUP'/>
</f:facet>
<h:outputText value="#{item.importeCup}"/>
<f:facet name="footer">
<h:outputText value="#{listadoFacturasMB.sumaCUP}"/>
</f:facet>
</p:column>
<p:column style="width:10%" id="cjj3">
<f:facet name="header">
<h:outputText value='Importe CUC'/>
</f:facet>
<h:outputText value="#{item.importeCuc}"/>
<f:facet name="footer">
<h:outputText value="#{listadoFacturasMB.sumaCUC}"/>
</f:facet>
</p:column>
</p:dataTable>
支持bean:
public void filterListener(FilterEvent filterEvent) {
try {
sumaTotal = new BigDecimal(0);
sumaCUP = new BigDecimal(0);
sumaCUC = new BigDecimal(0);
for (int i = 0; i < filterFacturaUtilList.size(); i++) {
FacturaUtil facturaUtil = filterFacturaUtilList.get(i);
this.sumaTotal = this.sumaTotal.add(facturaUtil.getImporteTotal());
this.sumaCUP = this.sumaCUP.add(facturaUtil.getImporteCup());
this.sumaCUC = this.sumaCUC.add(facturaUtil.getImporteCuc());
}
this.sumaTotal = this.sumaTotal.setScale(2, RoundingMode.HALF_UP);
this.sumaCUP = this.sumaCUP.setScale(2, RoundingMode.HALF_UP);
this.sumaCUC = this.sumaCUC.setScale(2, RoundingMode.HALF_UP);
} catch (Exception e) {
JsfUtil.addErrorMessage(e, "Error: filterListener() " + e.getMessage());
}
}