2013-03-26 93 views
0

我從數據庫中的類文件中的DB查詢:安排從迭代結果到表JSP

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> 

回答

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>