wood burning stoves 2.0*
The moose likes JSP and the fly likes How to use Break / exist statement here in foreach (JSTL) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to use Break / exist statement here in foreach (JSTL)" Watch "How to use Break / exist statement here in foreach (JSTL)" New topic
Author

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

saravanan sambandam
Ranch Hand

Joined: Aug 30, 2010
Posts: 42
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.


[Thumbnail for getting duplicate.JPG]

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Turn your list into a Set - that will guarantee no duplicates and will not require any ugly logic in your JSP.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
saravanan sambandam
Ranch Hand

Joined: Aug 30, 2010
Posts: 42
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.
 
Consider Paul's rocket mass heater.
 
subject: How to use Break / exist statement here in foreach (JSTL)