原值我在JSF的DataTable具有页脚的发票总额。我使用了一种方法来计算页面加载的总数,并且工作正常。数据表中的每一行都有一个复选框。当用户选中或取消选中该复选框的页面应该如果未选中此复选框减去该行的成本或增加成本占总若检验重新计算总。我试着添加另一个输出文本来保存新的总数并在相同的输出文本中更改值。问题是新的总没有得到渲染到输出文本。如何改变的outputText
我有一个静态变量来保存总因为它的变化。我也尝试过使用一种方法。在豆
private static BigDecimal saveInvoiceTotal;
InvoiceTotal方法
public BigDecimal invoiceTotal() throws Exception {
List<OrderDetail> selected = getDetails();
BigDecimal invoiceTotal = new BigDecimal(0);
for(OrderDetail d : selected) {
if(d.isSelected())
invoiceTotal = invoiceTotal.add(d.getExtCost());
else
invoiceTotal = invoiceTotal.subtract(d.getExtCost());
}
saveInvoiceTotal = invoiceTotal;
return invoiceTotal;
}
此方法用于新的总返回页面。
public BigDecimal invoiceSelectedTotal() throws Exception {
return saveInvoiceTotal;
}
这种方法加上或减去取决于成本上,如果复选框被选中或取消选中
public void selectedRow(OrderDetail d) throws Exception {
if(d.isSelected())
saveInvoiceTotal = saveInvoiceTotal.add(d.getExtCost());
else
saveInvoiceTotal = saveInvoiceTotal.subtract(d.getExtCost());
}
的确定年代
on page load <rich:dataTable id="detailTable" var="_detail" value="#{orderDetails.details}" rendered="#{not empty orderDetails.details}" style="width : 100%">
<rich:column id="detail_itemnumber">
<f:facet name="header">Item Number</f:facet>
#{_detail.itemNumber}
<f:facet name="footer">
<h:outputText value="Invoiced Total: " />
<h:outputText id="invTotal" value="#{orderDetails.invoiceTotal()}" rendered="#{_detail.invoiceRender}"/>
<h:outputText id="invSelectedTotal" value="#{orderDetails.invoiceSelectedTotal()}" rendered="#{not _detail.invoiceRender}"/>
</f:facet>
</rich:column>
<rich:column id="detail_extcost">
<f:facet name="header">Ext Cost</f:facet>
#{_detail.extCost}
<f:facet name="footer">
<h:outputText value="Order Total: " />
<h:outputText value="#{orderDetails.orderTotal()}" />
</f:facet>
</rich:column>
<rich:column id="detail_selected">
<f:facet name="header">Select</f:facet>
<h:selectBooleanCheckbox value="#{_detail.selected}" >
<f:param name="orderNo" value="#{order.id}"></f:param>
<a4j:ajax listener="#{orderDetailController.selectedRow(_detail)}" />
</h:selectBooleanCheckbox>
</rich:column>
</rich:dataTable>
好点。我试过了。使用上述selectedRow上面的方法我称之为invoiceSelectedTotal并返回新的总,但页面不显示新值。 – user4190199 2014-10-31 19:28:03