• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic