【问题标题】:Arrange result from Iterate into Table JSP将 Iterate 的结果排列到 Table JSP 中
【发布时间】:2013-03-26 03:44:18
【问题描述】:

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

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>

【问题讨论】:

    标签: loops jsp html-table iteration


    【解决方案1】:

    您可以将 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>
    

    【讨论】:

      猜你喜欢
      • 2016-07-28
      • 1970-01-01
      • 2013-04-09
      • 2016-12-06
      • 1970-01-01
      • 2019-03-05
      • 2012-08-12
      • 2014-07-18
      • 1970-01-01
      相关资源
      最近更新 更多