Sorting entries in a Select

Hi there,

The data source feeding my Select gives me un non-sorted result-set (e.g. Paris, Amsterdam, New-York). Is there a simple way to sort the entries (say alphabetically) at component level (to display Amsterdam, New-York, Paris to the user) ?

Thanks in advance,

Damien

You can use the container to sort the items. For example, if your select uses an IndexedContainer (which implements Container.Sortable), then you can use the sort() method to sort your items.

Hi Kim,

I changed

            List<DataObject> l = getObjectListFromDb();
            for (DataObject r: l){
            	select.addItem(r);
            }
            if (l.size()>0){
            	select.select(l.get(0));
            }

Into

            Collection<DataObject> l = getObjectListFromDb();
            BeanItemContainer c = new BeanItemContainer(l);

            c.sort(new String[]{"dataObjectIndex"}, new boolean[]
{true});
            select.setContainerDataSource(c);
            
            if (c.size()>0){
            	select.select(c.firstItemId());
            }

and it works as expected.

Thanks a lot,

Damien