diff options
author | Jarno Rantala <jarno.rantala@vaadin.com> | 2013-12-11 15:31:30 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2013-12-16 13:07:52 +0000 |
commit | 681864fee3c95dd281493f881db276b7b7abe87d (patch) | |
tree | 1e3d793ec7cbee3931543f32430ed9c971e56248 /server/src | |
parent | 1dd2ed36b73404f17863765ec34a56f8fdb0b40f (diff) | |
download | vaadin-framework-681864fee3c95dd281493f881db276b7b7abe87d.tar.gz vaadin-framework-681864fee3c95dd281493f881db276b7b7abe87d.zip |
Backported null value support for NestedMethodProperty to 7.1 (#12884)
Support for null values in NestedMethodProperty was already implemented in master branch (#11435)
This changeset includes changesets made for that.
Change-Id: I10696467f792e234326075bbcdd5aad487905a7e
Merge: no
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/data/util/AbstractBeanContainer.java | 10 | ||||
-rw-r--r-- | server/src/com/vaadin/data/util/BeanItem.java | 9 | ||||
-rw-r--r-- | server/src/com/vaadin/data/util/NestedMethodProperty.java | 10 |
3 files changed, 19 insertions, 10 deletions
diff --git a/server/src/com/vaadin/data/util/AbstractBeanContainer.java b/server/src/com/vaadin/data/util/AbstractBeanContainer.java index 35403d6419..b19cdd980c 100644 --- a/server/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/server/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -836,8 +836,9 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends * Adds a nested container property for the container, e.g. * "manager.address.street". * - * All intermediate getters must exist and must return non-null values when - * the property value is accessed. + * All intermediate getters must exist and should return non-null values + * when the property value is accessed. If an intermediate getter returns + * null, a null value will be returned. * * @see NestedMethodProperty * @@ -854,8 +855,9 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends * property to the container. The named property itself is removed from the * model as its subproperties are added. * - * All intermediate getters must exist and must return non-null values when - * the property value is accessed. + * All intermediate getters must exist and should return non-null values + * when the property value is accessed. If an intermediate getter returns + * null, a null value will be returned. * * @see NestedMethodProperty * @see #addNestedContainerProperty(String) diff --git a/server/src/com/vaadin/data/util/BeanItem.java b/server/src/com/vaadin/data/util/BeanItem.java index fc51be8f36..49f5f95898 100644 --- a/server/src/com/vaadin/data/util/BeanItem.java +++ b/server/src/com/vaadin/data/util/BeanItem.java @@ -255,12 +255,13 @@ public class BeanItem<BT> extends PropertysetItem { } /** - * Adds a nested property to the item. + * Adds a nested property to the item. The property must not exist in the + * item already and must of form "field1.field2" where field2 is a field in + * the object referenced to by field1. If an intermediate property returns + * null, the property will return a null value * * @param nestedPropertyId - * property id to add. This property must not exist in the item - * already and must of of form "field1.field2" where field2 is a - * field in the object referenced to by field1 + * property id to add. */ public void addNestedProperty(String nestedPropertyId) { addItemProperty(nestedPropertyId, new NestedMethodProperty<Object>( diff --git a/server/src/com/vaadin/data/util/NestedMethodProperty.java b/server/src/com/vaadin/data/util/NestedMethodProperty.java index b62ecfbfc3..8fe3b9d4c5 100644 --- a/server/src/com/vaadin/data/util/NestedMethodProperty.java +++ b/server/src/com/vaadin/data/util/NestedMethodProperty.java @@ -31,8 +31,9 @@ import com.vaadin.data.util.MethodProperty.MethodException; * The property is specified in the dotted notation, e.g. "address.street", and * can contain multiple levels of nesting. * - * When accessing the property value, all intermediate getters must return - * non-null values. + * When accessing the property value, all intermediate getters must exist and + * should return non-null values when the property value is accessed. If an + * intermediate getter returns null, a null value will be returned. * * @see MethodProperty * @@ -76,6 +77,8 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> { * Constructs a nested method property for a given object instance. The * property name is a dot separated string pointing to a nested property, * e.g. "manager.address.street". + * <p> + * Calling getValue will return null if any intermediate getter returns null * * @param instance * top-level bean to which the property applies @@ -199,6 +202,9 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> { Object object = instance; for (Method m : getMethods) { object = m.invoke(object); + if (object == null) { + return null; + } } return (T) object; } catch (final Throwable e) { |