summaryrefslogtreecommitdiffstats
path: root/server/src/com
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-09-29 20:40:36 +0300
committerVaadin Code Review <review@vaadin.com>2014-12-02 18:01:12 +0000
commit654846837379db9a76823f5d0e73e5e6bfa8115d (patch)
tree248f7bf34d6bdc054b6f3c84002481a4018b7b43 /server/src/com
parent3cad153ba405fa60583925db7fee111ec326794f (diff)
downloadvaadin-framework-654846837379db9a76823f5d0e73e5e6bfa8115d.tar.gz
vaadin-framework-654846837379db9a76823f5d0e73e5e6bfa8115d.zip
Allow BeanFieldGroup.setItemDataSource() method accept null (#14731).
Change-Id: I7a451f428f0aa3ea7fc322cac6b0e62d830d7987
Diffstat (limited to 'server/src/com')
-rw-r--r--server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java7
-rw-r--r--server/src/com/vaadin/data/util/BeanItem.java25
-rw-r--r--server/src/com/vaadin/data/util/MethodProperty.java10
3 files changed, 35 insertions, 7 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
index e5d53b759d..1f3ee36d58 100644
--- a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
+++ b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
@@ -130,16 +130,17 @@ public class BeanFieldGroup<T> extends FieldGroup {
* The bean to use as data source.
*/
public void setItemDataSource(T bean) {
- setItemDataSource(new BeanItem(bean));
+ setItemDataSource(new BeanItem<T>(bean, beanType));
}
@Override
public void setItemDataSource(Item item) {
- if (!(item instanceof BeanItem)) {
+ if (item == null || (item instanceof BeanItem)) {
+ super.setItemDataSource(item);
+ } else {
throw new RuntimeException(getClass().getSimpleName()
+ " only supports BeanItems as item data source");
}
- super.setItemDataSource(item);
}
@Override
diff --git a/server/src/com/vaadin/data/util/BeanItem.java b/server/src/com/vaadin/data/util/BeanItem.java
index 12d9b23d0a..64f30261c2 100644
--- a/server/src/com/vaadin/data/util/BeanItem.java
+++ b/server/src/com/vaadin/data/util/BeanItem.java
@@ -62,7 +62,30 @@ public class BeanItem<BT> extends PropertysetItem {
*
*/
public BeanItem(BT bean) {
- this(bean, getPropertyDescriptors((Class<BT>) bean.getClass()));
+ this(bean, (Class<BT>) bean.getClass());
+ }
+
+ /**
+ * <p>
+ * Creates a new instance of <code>BeanItem</code> and adds all properties
+ * of a Java Bean to it. The properties are identified by their respective
+ * bean names.
+ * </p>
+ *
+ * <p>
+ * Note : This version only supports introspectable bean properties and
+ * their getter and setter methods. Stand-alone <code>is</code> and
+ * <code>are</code> methods are not supported.
+ * </p>
+ *
+ * @param bean
+ * the Java Bean to copy properties from.
+ * @param beanClass
+ * class of the {@code bean}
+ *
+ */
+ public BeanItem(BT bean, Class<BT> beanClass) {
+ this(bean, getPropertyDescriptors(beanClass));
}
/**
diff --git a/server/src/com/vaadin/data/util/MethodProperty.java b/server/src/com/vaadin/data/util/MethodProperty.java
index 5e6b731571..853f68b711 100644
--- a/server/src/com/vaadin/data/util/MethodProperty.java
+++ b/server/src/com/vaadin/data/util/MethodProperty.java
@@ -132,7 +132,7 @@ public class MethodProperty<T> extends AbstractProperty<T> {
setArguments(getArgs, setArgs, setArgumentIndex);
String name = (String) in.readObject();
Class<?>[] paramTypes = SerializerHelper.readClassArray(in);
- if (name != null) {
+ if (instance != null && name != null) {
setMethod = instance.getClass().getMethod(name, paramTypes);
} else {
setMethod = null;
@@ -140,7 +140,7 @@ public class MethodProperty<T> extends AbstractProperty<T> {
name = (String) in.readObject();
paramTypes = SerializerHelper.readClassArray(in);
- if (name != null) {
+ if (instance != null && name != null) {
getMethod = instance.getClass().getMethod(name, paramTypes);
} else {
getMethod = null;
@@ -589,7 +589,11 @@ public class MethodProperty<T> extends AbstractProperty<T> {
@Override
public T getValue() {
try {
- return (T) getMethod.invoke(instance, getArgs);
+ if (instance == null) {
+ return null;
+ } else {
+ return (T) getMethod.invoke(instance, getArgs);
+ }
} catch (final Throwable e) {
throw new MethodException(this, e);
}