0 Replies Latest reply on Dec 3, 2009 8:36 AM by gtludwig

    sum and average calculation for <rich:dataTable> rows

    gtludwig

      Hello,

      I have successfully build a matrix using <rich:dataTable>. This matrix has a dynamic number of rows and columns. Each matrix cell has a <rich:inplaceSelect> element with 3 possible values {0, 5, 10}.

      Also there are 3 fixed columns per row. First column is the row identification. The last two columns represent a sum of the all the values the user selects with the <rich:inplaceSelect> and an average value calculated from the sum cell divided by the number of dynamic columns.

      I need that each time a <rich:inplaceSelect> value changes the sum value and average value for the given row also changes.

      The dataTable is defined as bellow:

      <rich:dataTable
       value="#{anamanMatrixMB.mechanicSysOutputs}"
       var="mechanic"
       rowKeyVar="rowNumber">
       <f:facet name="header">
       <h:outputText value="#{bundle['matrixTab.title']}" />
       </f:facet>
      
       <rich:column
       width="50">
       <h:outputText value="#{bundle['matrixLabel.mec']}#{rowNumber+1}"/>
       </rich:column>
      
       <rich:columns
       value="#{anamanMatrixMB.equipmentOutputs}"
       var="equip"
       index="ind"
       width="50" >
       <f:facet name="header">
       <h:outputText value="#{bundle['matrixLabel.equip']} #{ind+1}" />
       </f:facet>
       <rich:inplaceSelect
       value="#{anamanMatrixMB.selectedCorrValue}"
       selectWidth="50"
       defaultLabel="0" >
       <f:selectItems value="#{anamanMatrixMB.corrValues}" />
       <a4j:support
       event="onchange"
       reRender="rowSum"
       immediate="true" />
       </rich:inplaceSelect>
       </rich:columns>
      
       <rich:column width="125">
       <f:facet name="header">
       <h:outputText value="#{bundle['matrixTab.sum']}" />
       </f:facet>
       <h:outputText id="rowSum" value="#{anamanMatrixMB.sum}"/>
       </rich:column>
      
       <rich:column>
       <f:facet name="header">
       <h:outputText value="#{bundle['matrixTab.avg']}" />
       </f:facet>
       <h:outputText value="#{anamanMatrixMB.avg}"/>
       </rich:column>
      
      </rich:dataTable>
      


      What is the best approach to solve this? I figured two ways to do it:
      1) try and pass the row and column values to a backing bean valueChangeListener method.
      2) insert the <rich:inplaceSelect> component programatically and implement FacesContext()...renderResponse() there.

      please advise!

      Thanks in advance!
      gtludwig