In my spring web application I have arraylist in model attribute which I want to show in table format in JSP. I need to arrange the list items in the two columns dynamically. Below is code which creates only one column but I need to arrange then in even odd pair in two columns.
<table>
<c:forEach items="${artifact.answerOptions}" var="answeroption" varStatus="status">
<tr>
<td>
<form:radiobutton path="choosenAnswers" value="${answeroption}"/>
<label for="choosenAnswers" class="lowerlabel"><c:out value="${answeroption.answerText}"/></label>
</td>
</tr>
</c:forEach>
</table>
Here answerOptions is the list of AnswerOption beans which has answerText property.
Above code creates table but with one column, but I need them to arrange in even odd manner like below:
<table>
<tr>
<td> List Item 1</td>
<td> List Item 2</td>
</tr>
<tr>
<td> List Item 3</td>
<td> List Item 4</td>
</tr>
<tr>
<td> List Item 5</td>
<td> List Item 6</td>
</tr>
</table>
Use the
begin,endandstepattributes instead. You could let it iterate by 2 and get the list items by index directly.(no this doesn’t throw
ArrayIndexOutOfBoundsExceptionwhen you have odd amount of items)