Skip to content

Instantly share code, notes, and snippets.

@Crydust
Last active March 3, 2016 08:29
Show Gist options
  • Save Crydust/ce926e3aff0a723b6799 to your computer and use it in GitHub Desktop.
Save Crydust/ce926e3aff0a723b6799 to your computer and use it in GitHub Desktop.
show items in columns table jsp
<c:if test="${not empty items}">
<c:set var="itemColumns" value="3" />
<table border="1">
<tr>
<c:forEach items="${items}" var="item" varStatus="itemStatus">
<td><c:out value="${item}" /></td>
<c:if test="${itemStatus.index % itemColumns eq itemColumns - 1}"></tr><tr></c:if>
</c:forEach>
<c:if test="${fn:length(items) % itemColumns gt 0}">
<td colspan="${itemColumns - (fn:length(items) % itemColumns)}">&nbsp;</td>
</c:if>
</tr>
</table>
</c:if>
<c:if test="${not empty items}">
<c:set var="itemColumns" value="3" />
<table border="1">
<c:forEach items="${items}" var="item" varStatus="itemStatus">
<c:if test="${itemStatus.index % itemColumns eq 0"><tr></c:if>
<td><c:out value="${item}" /></td>
<c:if test="${itemStatus.last and (fn:length(items) % itemColumns gt 0)}">
<td colspan="${itemColumns - (fn:length(items) % itemColumns)}">&nbsp;</td>
</c:if>
<c:if test="${itemStatus.last or (itemStatus.index % itemColumns eq itemColumns - 1)}"></tr></c:if>
</c:forEach>
</table>
</c:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment