Solved

way to print in alp order??

Posted on 2011-09-08
10
309 Views
Last Modified: 2012-05-12
Hi,

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="${site.name}">
               <a href="${site.url}" target="_blank" class="${site.tag}">${site.name}</a>
            </li>
         </ul></td>                          
    <td style="width:25%">${site.lastUpdate } </td></tr>
</c:forEach>

Open in new window

0
Comment
Question by:dkim18
  • 4
  • 3
  • 3
10 Comments
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
like this?
http://stackoverflow.com/questions/712046/jstl-foreach-reverse-order

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

Assisted Solution

by:rrz
rrz earned 100 total points
Comment Utility
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.
0
 

Author Comment

by:dkim18
Comment Utility
If you can show me an example code, it will be very helpful.
If you could show me one that is not too hard!
0
 

Author Comment

by:dkim18
Comment Utility
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..
0
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
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);
%>
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:dkim18
Comment Utility
OK.
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...
      }

0
 

Author Comment

by:dkim18
Comment Utility
There is no Collections.sort() so are you saying I need to use Comparable <Site> =...?
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 400 total points
Comment Utility
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
>I can see the Site class  
If you want more help, then please show us that code.
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
Also, tell us how you want to sort the List of sites.  On the name = site.getName() ?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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 first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now