开发者

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>:

  1. 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 the ManfacturerIssue is a javabean class which contains Integer number and String issue properties. This way you can end up doing:

    <c:forEach items="${mfgIssues}" var="mfgIssue">
        ${mfgIssue.number}, ${mfgIssue.issue}
    </c:forEach>
    
  2. 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>
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜