0

I am using the following code to remove the duplicates from a list of email id's while populating the dropdown. If circleList contains 10 records and has 3 duplicates, then those 3 are replaced with an empty string (i.e., still showing 10 records) but the expected output is a dropdown with 7 records.

<select name="ccOfficialMailId" id="ccOfficialMailId"
style="width: 150px">
<option value="">-- Please select EmailId --</option>
<core:forEach var="item" items="${circleList}" varStatus="status">
<core:set var="emailAlreadyExists" value="${false}" />
<core:if test="${(status.index-1) > 0}">
<core:forEach var="previousEmail" items="${circleList}" begin="0"
end="${status.index-1}" varStatus="inner">
<core:if
test="${item.ccOfficialEmail == previousEmail.ccOfficialEmail}">
<core:set var="emailAlreadyExists" value="${true}" />
</core:if>
</core:forEach>
</core:if>
<core:if test="${not emailAlreadyExists}">
<option value="${item.ccOfficialEmail}">${item.ccOfficialEmail}</option>
</core:if>
</core:forEach>
</select>

How could I achieve this?

ShellZero
  • 4,415
  • 12
  • 38
  • 56
  • please help me to remove the email if from the dropdown instead of replacing with empty string. – divya rajamohan Jun 08 '17 at 17:07
  • Use Java code, in your controller, to provide a duplicate-free list to your view. That's the job of the controller, not the job of the view. – JB Nizet Jun 08 '17 at 17:08
  • each list contains a bean object with 5 to 6 properties and are populated using spring jdbc and mapper. so removing duplicates in controller is difficult. – divya rajamohan Jun 08 '17 at 17:49
  • If it's difficult in Java, with all the expressiveness of the language and all the available APIs, how could it be simpler in the JSP, where you only have very limited capabilities? – JB Nizet Jun 08 '17 at 18:05
  • i agree, but am trying to find if there is any way to make the above code efficient so that the expected result can be achieved as i am able to remove the duplicates but it is getting replaced with empty string. – divya rajamohan Jun 08 '17 at 18:12
  • as in this particular case of project, handling it in jsp is easier compared to java. – divya rajamohan Jun 08 '17 at 18:13
  • 1
    JSP is meant for serving the cooked output just for making UI, it is never recommended to put the business logic or other manipulation related code in jsp. Do all the filtering in your controller and then send the ready-to-display list to jsp. – Shailesh Saxena Jun 09 '17 at 05:42
  • If you are really intended to do that, let me know how circleList and ccOfficialMailId are connected to each other? have a look here: https://stackoverflow.com/questions/8464552/how-to-eliminate-duplicate-values-in-jsp-expression-language – Shailesh Saxena Jun 09 '17 at 05:53

0 Answers0