Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with nested loop (c:forEach) tags. Can I break from inner loop?

843838Feb 13 2006 — edited Feb 13 2006
Hi all, I have this annoying problem and I am looking for any suggestions.

I have 2 select boxes. One is for all available users, and second - for selected users (designated as admins). The list of all users is available in a collection (2 properties userId and userName displayed in the code below). The list of admins contains only userId (as strings).

I have no problem with populating selected users (admins) list, reusing pretty much the same logic below, but I cannot find a way to break out from the nested loop once the match is found, to avoid repetitions leading to incorrect display of results.
<select name=available>
<c:forEach items="${users}" var="user" varStatus="outer">
    <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
        <c:if test="${user.userId!=adminId">
             <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
        </c:if>
    </c:forEach>
</c:forEach>
</select>

<select name=selected>
<c:forEach items="${users}" var="user" varStatus="outer">
    <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
        <c:if test="${user.userId==adminId">
             <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
        </c:if>
    </c:forEach>
</c:forEach>
</select>
Can anyone help, please? I am also restricted to JSP 1.2
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 13 2006
Added on Feb 13 2006
2 comments
664 views