way to print in alp order??

Posted on 2011-09-08
Last Modified: 2012-05-12

How can I sort items, items='${company.sites}' in alphabetical order and print them?
Do I need to sort it in Java class first?

<c:forEach items='${company.sites}' var="site">
  <tr><td><ul><li class="${}">
               <a href="${site.url}" target="_blank" class="${site.tag}">${}</a>
    <td style="width:25%">${site.lastUpdate } </td></tr>

Open in new window

Question by:dkim18
  • 4
  • 3
  • 3
LVL 40

Expert Comment

ID: 36503985
like this?

i guess you need to sort the collection in servlet, before you get to jsp
LVL 27

Assisted Solution

rrz earned 100 total points
ID: 36504358
You could order the sites when you put them into your collection,
or you could create a tag file to do the sorting,
or you could create a custom EL function to do the sorting. Please ask us here, if you want example code.

Author Comment

ID: 36504768
If you can show me an example code, it will be very helpful.
If you could show me one that is not too hard!
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

ID: 36504800
I have a basic java question, ${company.sites}
I can see the Site class but I can't find the Sites class.
I can't find where Sites collection is.
How does this servlet  syntax work?
I have this Java project and trying to understand what it is doing and fix bugs if I can..
LVL 40

Expert Comment

ID: 36504944
you can simply include this scriptlet in your code

List list = (List)session.getAttribute("company.sites");
Comparator comp = .... //comparator class defined to sort the sites
Collections.sort(list, comp);

Author Comment

ID: 36505357
I came to understand that Com
Company class {
Company company;

public List<String> getOwnerNames() {
        List<String> owners = LuceneConfig.getOwnernames();
        return Collections.sort( owners );

public List<Site> getSites() {
       List<Site> xsites = LuceneConfig.getSites();
       return  Collections.sort(xsites);  <=== I need help this part...


Author Comment

ID: 36505369
There is no Collections.sort() so are you saying I need to use Comparable <Site> =...?
LVL 40

Accepted Solution

gurvinder372 earned 400 total points
ID: 36505619
LVL 27

Expert Comment

ID: 36506869
>I can see the Site class  
If you want more help, then please show us that code.
LVL 27

Expert Comment

ID: 36506885
Also, tell us how you want to sort the List of sites.  On the name = site.getName() ?

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
difference of if loops 23 62
reverse digits of a number using for loop 5 52
how to debug htl and js pages 8 39
Tagging and Merging on Branch 1 29
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question