• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

way to print in alp order??

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
dkim18
Asked:
dkim18
  • 4
  • 3
  • 3
2 Solutions
 
Gurvinder Pal SinghCommented:
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
 
rrzCommented:
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
 
dkim18Author Commented:
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
Industry Leaders: 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!

 
dkim18Author Commented:
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
 
Gurvinder Pal SinghCommented:
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
 
dkim18Author Commented:
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
 
dkim18Author Commented:
There is no Collections.sort() so are you saying I need to use Comparable <Site> =...?
0
 
rrzCommented:
>I can see the Site class  
If you want more help, then please show us that code.
0
 
rrzCommented:
Also, tell us how you want to sort the List of sites.  On the name = site.getName() ?
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now