It seems like an "instanceof String" followed by downcasts and
String#compareToIgnoreCase should do the trick.

On Fri, Jun 24, 2011 at 12:30 AM, pragya.rawal <pragya.ra...@gmail.com>wrote:

> Hi,
>
> I have a DataView and I am sorting data column (on click of column header)
> inside it using my custom SortableTaskDataProvider which extends
> SortableDataProvider.
>
> So, I pass the property name (column) and DataView (list) and I get the
> list
> sorted on the basis of property.
>
> So, as per the default implementation of compareTo, it sorts Saring
> starting
> with Capital letters first and the the ones that start with lower case.
>
> I require to write a comparator which sorts irrespective of the case (upper
> or lower), but the problem I am facing is that the setSort() method
> provided
> by wicket takes the property name.
>
> Is there any way where I can specify that if the property is of type
> String,
> it should sort without considering the case.
>
> Below is my code for SortableTaskDataProvider
>
>
> public class SortableTaskDataProvider extends
> SortableDataProvider<BaseTaskModel> {
>
>    private static final long serialVersionUID = 1L;
>    private List<BaseTaskModel> list = new ArrayList<BaseTaskModel>();
>
>    public SortableTaskDataProvider(List<BaseTaskModel> list) {
>        super();
>        setSort("createdBy", false);
>        this.list = list;
>    }
>
>    @Override
>    public Iterator<? extends BaseTaskModel> iterator(int first, int count)
> {
>        List<BaseTaskModel> newList = new ArrayList<BaseTaskModel>(list);
>
>        Collections.sort(newList, new Comparator<BaseTaskModel>() {
>
>            @SuppressWarnings("rawtypes")
>            @Override
>            public int compare(BaseTaskModel o1, BaseTaskModel o2) {
>                PropertyModel<Comparable> model1 = new
> PropertyModel<Comparable>(o1, getSort().getProperty());
>                PropertyModel<Comparable> model2 = new
> PropertyModel<Comparable>(o2, getSort().getProperty());
>
>                @SuppressWarnings("unchecked")
>                int result =
> model1.getObject().compareTo(model2.getObject());
>
>                if (!getSort().isAscending()) {
>                    result = -result;
>                }
>
>                return result;
>
>            }
>        });
>        return newList.subList(first, first + count).iterator();
>    }
>
>    @Override
>    public int size() {
>        if (list == null)
>            return 0;
>        return list.size();
>    }
>
>    @Override
>    public IModel<BaseTaskModel> model(final BaseTaskModel object) {
>        return new AbstractReadOnlyModel<BaseTaskModel>() {
>            private static final long serialVersionUID = 1L;
>
>            @Override
>            public BaseTaskModel getObject() {
>                return object;
>            }
>        };
>    }
> }
>
>
> Any pointers will be highly appreciated.
>
> Thanks,
> Pragya
> http://pragyarawal.co.cc
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Sorting-problem-tp3621869p3621869.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to