原值我在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