我在类文件中有来自数据库的数据库查询:
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.如果resultsize为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 :(得分:0)
您可以将indexId属性转换为页面上下文变量,并将其测试为可分性2;然后在奇数值上插入TR标记,在偶数值上插入end-TR-tag。像这样:
<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>