iterating of muliple items in jstl
I have this requirement to iterate over 3 lists at the same time in jstl. for iterating over a single list we use
<c:forEach var = "mfgn" items = "${requestScope.mfgNumber}" varStatus = "status">
do something;
</c:forEach>
I need to do some thing like
<c:forEach var = "mfgn" var = "issue" items = "${requestScope.mfgNumber}" items = "${requestScope.something" varStatus = "status">
mfgNumber;
</c:forEach>
is this possible or there an otherway to iterate over multiple lists at the开发者_开发知识库 same time.
If they have the same size, then there are two options, assuming that it are List<Integer>
and List<String>
:
Merge them in a single list with entities which in turn repesents the items of each other list in a single class like
List<ManfacturerIssue>
where theManfacturerIssue
is a javabean class which containsInteger number
andString issue
properties. This way you can end up doing:<c:forEach items="${mfgIssues}" var="mfgIssue"> ${mfgIssue.number}, ${mfgIssue.issue} </c:forEach>
Iterate by index instead, this is however ugly and unmaintainable as (fill in):
<c:forEach begin="0" end="${fn:length(mfgNumbers) - 1}" varStatus="loop"> ${mfgNumbers[loop.index]}, ${issues[loop.index]} </c:forEach>
精彩评论