File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply 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
Greenhorn

Joined: Aug 30, 2010
Posts: 24
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: 56150
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
saravanan sambandam
Greenhorn

Joined: Aug 30, 2010
Posts: 24
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.
 
I agree. Here's the link: jrebel
 
subject: How to use Break / exist statement here in foreach (JSTL)
 
Similar Threads
check boxes retrieving problem
Implementation of google charts in JSP
Best choice for pagination?
Maintain checked checkbox status
pass jstl value to javascript