summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2009-05-08 14:36:01 +0000
committerArtur Signell <artur.signell@itmill.com>2009-05-08 14:36:01 +0000
commit36ff35c304321ff4cfd4221cdc9ccf4c2d9f64ff (patch)
tree504054a100b839a4630b26623a89594846e1d91e
parentc409e55e940a89bcea658ef5bd2b1ea098fd2005 (diff)
downloadvaadin-framework-36ff35c304321ff4cfd4221cdc9ccf4c2d9f64ff.tar.gz
vaadin-framework-36ff35c304321ff4cfd4221cdc9ccf4c2d9f64ff.zip
Fix for #2917 - BeanItemContainer.sort fails if property value is null
svn changeset:7691/svn branch:6.0
-rw-r--r--src/com/itmill/toolkit/data/util/BeanItemContainer.java31
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);
}
});
}