2014-10-30 31 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; 
}