diff options
-rw-r--r-- | src/com/itmill/toolkit/data/util/BeanItemContainer.java | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/com/itmill/toolkit/data/util/BeanItemContainer.java b/src/com/itmill/toolkit/data/util/BeanItemContainer.java index 99e42e7e76..a2df599df2 100644 --- a/src/com/itmill/toolkit/data/util/BeanItemContainer.java +++ b/src/com/itmill/toolkit/data/util/BeanItemContainer.java @@ -394,12 +394,31 @@ public class BeanItemContainer<BT> implements Indexed, Sortable, Filterable, Collections.sort(allItems, new Comparator<BT>() { @SuppressWarnings("unchecked") public int compare(BT a, BT b) { - Comparable va = (Comparable) beanToItem.get(a) - .getItemProperty(property).getValue(); - Comparable vb = (Comparable) beanToItem.get(b) - .getItemProperty(property).getValue(); - - return asc ? va.compareTo(vb) : vb.compareTo(va); + Comparable va, vb; + if (asc) { + va = (Comparable) beanToItem.get(a).getItemProperty( + property).getValue(); + vb = (Comparable) beanToItem.get(b).getItemProperty( + property).getValue(); + } else { + va = (Comparable) beanToItem.get(b).getItemProperty( + property).getValue(); + vb = (Comparable) beanToItem.get(a).getItemProperty( + property).getValue(); + } + + /* + * Null values are considered less than all others. The + * compareTo method cannot handle null values for the + * standard types. + */ + if (va == null) { + return (vb == null) ? 0 : -1; + } else if (vb == null) { + return (va == null) ? 0 : 1; + } + + return va.compareTo(vb); } }); } |