0

我在类文件中有来自数据库的数据库查询:

List srActionList = hibernate_session.createQuery("from SrActionModal where srReportShow = 'Y' order by actDesc").list();

ArrayList dataResultList = new ArrayList();
SrActionModal status = new SrActionModal();

for (int i = 0; i < srActionList.size(); i++) {
    status = (SrActionModal) srActionList.get(i);
    status.setActDesc(status.getActDesc());
    dataResultList.add(status);
}
session.setAttribute("srActionList", dataResultList); 

我想将 srActionList 属性显示到表中。目前我的输出如下所示;

    <logic:iterate id="list" name="srActionList">
 <html:multibox property="selectedAction">
    <bean:write name="list" property='code'/>
 </html:multibox>
 <bean:write name="list" property='actDesc'/>
    </logic:iterate>

我的问题是,如何将结果安排到表格中以便更好地安排?每行的限制列是 2。如果结果大小是 10,那么将有 5 行,每行包含 2 列。

    <table>
     <tr> 
         <td>list 1</td> <td>list 2</td>
     </tr>
     <tr> 
         <td>list 3</td> <td>list 4</td>
     </tr>
    </table>
4

1 回答 1

0

您可以将 indexId 属性放入页面上下文变量中并测试它是否可被 2 整除;然后在奇数值上插入一个 TR 标签,在偶数值上插入一个结束 TR 标签。像这样的东西:

   <table>
   <logic:iterate id="list" name="srActionList" indexId="index">
      <% Integer index = (Integer) pageContext.getAttribute("index");
      /* If not divisible by 2 then insert a table row marker */
      if (index.intValue() % 2 == 1) { %>
      <tr>
      <% } %>
      <td>
         <html:multibox property="selectedAction">
         <bean:write name="list" property='code'/>
            </html:multibox>
         <bean:write name="list" property='actDesc'/>
      </td>
      <% Integer index = (Integer) pageContext.getAttribute("index");
      /* If divisible by 2 then insert a table row end marker */
      if (index.intValue() % 2 == 0) { %>
      </tr>
      <% } %>
   </logic:iterate>
   </table>
于 2013-03-26T05:00:03.430 回答