[英]arranging dynamic list in jsp page in the specified structure using table
i have a list which is dynamically generated.and i want this list should be displayed using table. 我有一个动态生成的列表。我希望使用表显示此列表。 the structure should be as follows 结构应如下
suppose if i have 6 values, the first 3 values should be in first row and second 3 should be in second row how can i do it dynamically 假设如果我有6个值,则前3个值应该在第一行中,而后3个值应该在第二行中,我该如何动态地进行操作
<table>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
the above tr structure should repeat for every 3 elements 上面的tr结构应该每3个元素重复一次
i tried doing with divs.its working but i want the same to be implemented using table. 我尝试使用divs.its工作,但我希望使用表来实现相同的目的。 help me out. 帮帮我。
regards, ravi. 问候,拉维。
what i mean to say is the list is a collection of beans.in each bean i had some values.so my table looks like as follows 我的意思是列表是bean的集合。在每个bean中我都有一些value.so,我的表如下所示
this is the list am iterating 这是正在迭代的列表
<c:forEach value="#{theList}" var="item">
<div class="customer">
<p>${item.field1}</p>
<p>${item.field1}</p>
</div>
</c:foreach>
from above the div customer should be in the structure as follows 从上面来看,div客户应具有以下结构
Using JSTL: 使用JSTL:
<table>
<c:forEach items="#{theList}" var="item" varStatus="i">
<c:if test="${i.index % 3 == 0 or i.begin}">
<tr>
</c:if>
<td>${item.field}</td>
<c:if test="${i.index % 3 == 0 or i.last}">
</tr>
</c:if>
</c:forEach>
</table>
<c:forEach items="${loopableObject}" var="theObject" varStatus="theCount">
<table>
<tr>
<c:if test='${(status.index) lt 3}'>
<td>${item.field1}</td>
<td>${item.field2}</td>
<td>${item.field3}</td>
</c:if>
</tr>
<tr>
<c:if test='${(status.index) gt 2}'>
<td>${item.field1}</td>
<td>${item.field2}</td>
<td>${item.field3}</td>
</c:if>
</tr>
</table>
</c:forEach>
While I haven't tested it, something like this might work. 虽然我还没有测试过,但类似的东西可能会起作用。
<table>
<tr>
<c:forEach var="item" items="${yourList}" varStatus="loopStatus">
<c:if test="${loopStatus.index % 3 == 0 }"><tr></c:if>
<td><c:out value="${item}"/></td>
<c:if test="${loopStatus.index % 3 == 0 }"></tr></c:if>
</c:forEach>
<c:if test="${yourList.size % 3 != 0 }"></tr></c:if>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.