2014-10-30 33 views
0

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

回答

0

您可以嘗試使用Ajax和回憶的方法每次當用戶檢查/ unckecs

+0

好點。我試過了。使用上述selectedRow上面的方法我稱之爲invoiceSelectedTotal並返回新的總,但頁面不顯示新值。 – user4190199 2014-10-31 19:28:03

0
The solution was to use <f:ajax render="invTotal"/> 


<rich:panel header="Order Detail">    
      <h:form> 
      <rich:dataTable value="#{data.details}" var="abc"> 
        <rich:column id="detail_itemnumber"> 
         <f:facet name="header"> 
          <h:outputText value="Item Number"/> 
         </f:facet> 
         <h:outputText value="#{abc.itemNumber}"/> 
         <f:facet name="footer"> 
        <h:outputText value="Invoiced Total: " /> 
        <h:outputText id="invTotal" value="#{data.invoiceTotal()}" /> 
        <!-- <h:outputText id="invSelectedTotal" value="#{abc.invoiceAmount}" rendered="#{not abc.invoiceRender}"/> -->      
        </f:facet>     
       </rich:column> 
       <rich:column> 
        <f:facet name="header"> 
         <h:outputText value="Item Description"/> 
        </f:facet> 
         <h:outputText value="#{abc.itemDesc}" /> 
       </rich:column> 
       <rich:column> 
        <f:facet name="header"> 
         <h:outputText value="Order Qty"/> 
        </f:facet> 
         <h:outputText value="#{abc.orderQty}" />       
       </rich:column> 
       <rich:column id="detail_invoiceqty" style="width : 10%"> 
        <f:facet name="header"> 
         <h:outputText value="Invoice Qty"/> 
        </f:facet> 
        <h:inputText value="#{abc.invoiceQty}" >       
         <f:ajax render="invTotal" /> 
         <a4j:ajax listener="#{data.calculateExtCost()}" render="extCost"/> 
        </h:inputText> 
       </rich:column> 
       <rich:column> 
        <f:facet name="header"> 
         <h:outputText value="Item Cost"/> 
        </f:facet> 
         <h:outputText value="#{abc.itemCost}" />      
       </rich:column> 
       <rich:column id="detail_extcost"> 
        <f:facet name="header"> 
         <h:outputText value="Ext Cost"/> 
        </f:facet> 
        <h:outputText id="extCost" value="#{abc.extCost}" /> 
        <f:facet name="footer"> 
         <h:outputText value="Order Total: " /> 
         <h:outputText value="#{data.orderTotal()}" />      
        </f:facet> 
       </rich:column> 
       <rich:column> 
        <f:facet name="header"> 
         <h:outputText value="Selected"/> 
        </f:facet> 
         <h:selectBooleanCheckbox value="#{abc.selected}" > 
          <!-- <a4j:ajax listener="#{data.invoiceTotal()}" /> --> 
          <f:ajax render="invTotal"/>        
         </h:selectBooleanCheckbox>      
       </rich:column>     
      </rich:dataTable> 

public BigDecimal invoiceTotal() throws Exception {   
    List<OrderDetail> selected = getDetails();  
    BigDecimal newInvoiceTotal = new BigDecimal(0);     

    for(OrderDetail d : selected) {   

     if(d.isSelected()) 
      newInvoiceTotal = newInvoiceTotal.add(d.getExtCost());      
    }  

    return newInvoiceTotal; 
}