• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Break / exist statement here in foreach (JSTL)

 
saravanan sambandam
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi frd,

while iterating collection object using Foreach by JSTL i am getting duplicates. How could stop the duplicate from the comparison point itself. If i used script let <% %> i can use break statement then i could avoid the duplicate. Please help me.

It urgent to my current project.




[code]
<tr>
<td> Objects</td>
<c:forEach var="OperationPojo" items="${OperationList}" >
<td> <c:out value="${OperationPojo.operation_name}" /> </td>
</c:forEach>

</tr>
<c:set value="${false}" var="unCheckFlag"></c:set>
<c:forEach var="ObjectPojo" items="${ObjectList}" >
<tr>
<td> <c:out value="${ObjectPojo.object_name}"/> </td>
<c:forEach var="OperationPojo" items="${OperationList}" >
<c:forEach var="UoopPOJO" items="${userPermissionList}" >
<c:if test="${UoopPOJO.pageId == ObjectPojo.object_id}">
<c:if test="${UoopPOJO.actId==OperationPojo.operation_id }">
<c:set value="${true}" var="unCheckFlag"></c:set>
<td align = "center"><c:out value="${ObjectPojo.object_id}" />,<c:out value="${OperationPojo.operation_id}"/>
<input type="checkbox" name="choose[]" value=<c:out value="${ObjectPojo.object_id}" />-<c:out value="${OperationPojo.operation_id}" /> checked="checked">
</td>
</c:if>
<c:if test="${UoopPOJO.actId!=OperationPojo.operation_id }">
<c:set value="${false}" var="unCheckFlag"></c:set>
</c:if>
</c:if>


</c:forEach>
<c:if test="${'unCheckFlag'== false}">
<td align = "center"><c:out value="${ObjectPojo.object_id}" />,<c:out value="${OperationPojo.operation_id}"/>
<input type="checkbox" name="choose[]" value=<c:out value="${ObjectPojo.object_id}" />-<c:out value="${OperationPojo.operation_id}" />>
</td>
</c:if>
</c:forEach>
</tr>
</c:forEach>
[/cdoe]


I have attached the screen shot of my result page. Here i had marked & colored the duplicate values.

Thanks
Saran.
getting duplicate.JPG
[Thumbnail for getting duplicate.JPG]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Turn your list into a Set - that will guarantee no duplicates and will not require any ugly logic in your JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul is spot on. In general it is always better to perform any data processing, including data cleansing, before you send it to the JSP. Keep the JSP as simple as possible.
 
saravanan sambandam
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the result from this piece of codes.

if any body struggle to exist the loop by using JSTL

please look into that.

http://java.ittoolbox.com/groups/technical-functional/javaee-l/jstl-break-possible-2144604

Thanks
Saran.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic