struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Søren Blidorf <so...@nolas.dk>
Subject SV: Sort a collection in alphabetic order
Date Mon, 10 Mar 2003 22:33:41 GMT
Thanks a million.

You just made my day.

Soren

-----Oprindelig meddelelse-----
Fra: Yan, Charlene [mailto:Charlene.Yan@thomsonlearning.com] 
Sendt: 10. marts 2003 23:12
Til: Struts Users Mailing List
Emne: RE: Sort a collection in alphabetic order 

Try this:

import org.apache.commons.beanutils.BeanComparator;

Collections.sort(people, new BeanComparator("lastname"));

Charlene

-----Original Message-----
From: Søren Blidorf [mailto:soren@nolas.dk]
Sent: Monday, March 10, 2003 4:33 PM
To: 'Struts Users Mailing List'
Subject: SV: Sort a collection in alphabetic order 


Sorry, but I can't get it to work.

Does any body have a simple example I can look at?

Soren

-----Oprindelig meddelelse-----
Fra: nash e. foster [mailto:nfoster@trusecure.com] 
Sendt: 10. marts 2003 19:27
Til: Struts Users Mailing List
Emne: Re: Sort a collection in alphabetic order 



You could have your PeopleBean implement Comparable, which is pretty 
easy, and then use TreeSet to create a sorted set using your compareTo 
method.

-nash

On Monday, March 10, 2003, at 01:16  PM, Søren Blidorf wrote:

>
> Hi.
> I need to sort my collection "people" in alphabetic order by lastname,
> firstname.
> Can anybody help me?
>
> I guess I should do it in the Action and not when displayed in jsp 
> page.
>
>
>
> Collection people = new ArrayList();
>
> while( rs.next() ) {
> PeopleBean pb = new PeopleBean();
> pb.setId(rs.getInt("ID"));
> pb.setFirstname( rs.getString( "FIRSTNAME" ));
> pb.setLastname( rs.getString( "LASTNAME" ));
> }
>
> people.add( pb );
>
>
> Søren Blidorf
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


***********************************************************************
This message is intended only for the use of the intended recipient and
may contain information that is PRIVILEGED and/or CONFIDENTIAL.  If you
are not the intended recipient, you are hereby notified that any use,
dissemination, disclosure or copying of this communication is strictly
prohibited.  If you have received this communication in error, please
destroy all copies of this message and its attachments and notify us
immediately.
***********************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message