Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

way to print in alp order??

Posted on 2011-09-08
10
Medium Priority
?
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36503985
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 28

Assisted Solution

by:rrz
rrz earned 400 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.
0
 

Author Comment

by:dkim18
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!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

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

Expert Comment

by:Gurvinder Pal Singh
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);
%>
0
 

Author Comment

by:dkim18
ID: 36505357
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
ID: 36505369
There is no Collections.sort() so are you saying I need to use Comparable <Site> =...?
0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 1600 total points
ID: 36505619
0
 
LVL 28

Expert Comment

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

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

610 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