3

在循环运行并填充数据表后,我想计算列的总数并将它们显示在最后一行。

这是我填充表格的代码......我需要构建最后一行:

<table class="data_table">
  <tr>
    <th>Source Of Issues</th>
    <th>First Issues</th>
    <th>second Issues</th>
    <th>Changes</th>
  </tr>

  <c:forEach var="bean" items="${beans}" varStatus="loopCount">
    <tr>
      <td><a href="foobar">${bean.sorCode}</a></td>
      <td class="right"><fmt:formatNumber value='${bean.firstissue}'
                             type="currency" groupingUsed='true' /></td>
      <td class="right"><fmt:formatNumber value='${bean.secondissue}'
                             type="currency" groupingUsed='true' /></td>
      <td class="right"><fmt:formatNumber value='${bean.changes}'
                             type="currency" groupingUsed='true' /></td>
    </tr>
  </c:forEach>  
</table>
4

2 回答 2

6
<c:set var="sum" value="${0}"/>     
<c:forEach var="bean" items="${beans}" varStatus="loopCount">
  <c:set var="total" value="${bean.actualLabor + bean.plannedLabor}"/>
  <tr>
    <td><a href="foobar">${bean.sorCode}</a></td>
    <td class="right"><fmt:formatNumber value='${bean.firstissue}' 
                           type="currency" groupingUsed='true' /></td>
    <td class="right"><fmt:formatNumber value='${bean.secondissue}'
                           type="currency" groupingUsed='true' /></td>
    <td class="right"><fmt:formatNumber value='${changes}'
                           type="currency" groupingUsed='true' /></td>
  </tr>
  <c:set var="sum" value="${sum + changes}"/>      
</c:forEach>

<fmt:formatNumber value='${sum}' type="currency" groupingUsed='true' />      
于 2012-09-12T13:50:37.910 回答
-1
    <table class="data_table">
    <tr>
        <th>Source Of Issues</th>
        <th>First Issues</th>
        <th>second Issues</th>
        <th>Changes</th>
    </tr>
    <c:set var="plannedSum" value="${0}"/>
    <c:set var="actualSum" value="${0}"/> 
    <c:set var="changesSum" value="${0}"/>   
    <c:forEach var="bean" items="${beans}" varStatus="loopCount">
    <c:set var="plannedSum" value="${plannedSum + bean.firstissue}"/>
    <c:set var="actualSum" value="${actualSum + bean.secondissue}"/>  
    <c:set var="changesSum" value="${changesSum + bean.changes}"/> 
        <tr>
            <td><a href="foobar">${bean.sorCode}</a></td>
            <td class="right"><fmt:formatNumber value='${bean.firstissue}' type="currency" groupingUsed='true' /></td>
            <td class="right"><fmt:formatNumber value='${bean.secondissue}' type="currency" groupingUsed='true' /></td>
            <td class="right"><fmt:formatNumber value='${bean.changes}' type="currency" groupingUsed='true' /></td>
       </tr>
     </c:forEach>
     <tr>
            <td><a>Totals</a></td>
            <td class="right"><fmt:formatNumber value='${plannedSum}' type="currency" groupingUsed='true' /></td>
            <td class="right"><fmt:formatNumber value='${actualSum}' type="currency" groupingUsed='true' /></td>
            <td class="right"><fmt:formatNumber value='${changesSum}' type="currency" groupingUsed='true' /></td>
    </tr>


</table>
于 2012-09-12T14:42:00.900 回答