• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to sort bean by value and ignore duplicates in JSTL ?  RSS feed

 
Jayaram Ponnusamy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to JSP. We are using below code to fetch the Data from CMS. But its not sorting the Lists. We want to Sort the List by the value (Not Native Sort).
Also if result having duplicate values then it has to be omit duplicate in the Output.



Currently its listing ${content.system.name} not sorting by ascending/descending. We want to sort this field by ${content.sortOrder}.

**Current Output:**
Copy Copy of Test External Link, 1.0
Test External Link, 5.0
Copy of Test External Link, 3.0
Test External Link, 5.0
Test External Link, 5.0
Copy of Our History, 2.0
Our History, 4.0

**Expecting Output:**
Copy Copy of Test External Link, 1.0
Copy of Our History, 2.0
Copy of Test External Link, 3.0
Our History, 4.0
Test External Link, 5.0
 
Paul Clapham
Sheriff
Posts: 22375
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest sorting and filtering the list in the place you generate that list, not in the JSP. Your Java code which generates the list will have much better facilities for sorting and filtering lists.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I would suggest sorting and filtering the list in the place you generate that list, not in the JSP. Your Java code which generates the list will have much better facilities for sorting and filtering lists.


Also, running a debugger against scriptlets in a JSP is a

In server java logic, use the java.lang.utilities sort function. You'll need a Comparator to tell it which which bean (if either) sorts higher than another bean. In Java 8 you'll probably be able to code this using a lambda.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!