]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed BindException when binding nested properties with BeanFieldGroup.buildAndBind...
authorJohn Ahlroos <john@vaadin.com>
Thu, 28 Feb 2013 10:07:35 +0000 (12:07 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 28 Feb 2013 10:43:24 +0000 (10:43 +0000)
Change-Id: I9bf646b7d8b767c78506a62185ce5dca9dcae7ad

server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java
server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java [new file with mode: 0644]

index 7e44c26c9edc2e6c21ca8146977c43340002d073..b0d03af8d636c0804e7cb3844696bf69e6531b90 100644 (file)
@@ -110,8 +110,7 @@ public class BeanFieldGroup<T> extends FieldGroup {
         return (BeanItem<T>) super.getItemDataSource();
     }
 
-    @Override
-    public void bind(Field field, Object propertyId) {
+    private void ensureNestedPropertyAdded(Object propertyId) {
         if (getItemDataSource() != null) {
             // The data source is set so the property must be found in the item.
             // If it is not we try to add it.
@@ -123,10 +122,21 @@ public class BeanFieldGroup<T> extends FieldGroup {
                 getItemDataSource().addNestedProperty((String) propertyId);
             }
         }
+    }
 
+    @Override
+    public void bind(Field field, Object propertyId) {
+        ensureNestedPropertyAdded(propertyId);
         super.bind(field, propertyId);
     }
 
+    @Override
+    public Field<?> buildAndBind(String caption, Object propertyId)
+            throws BindException {
+        ensureNestedPropertyAdded(propertyId);
+        return super.buildAndBind(caption, propertyId);
+    }
+
     @Override
     protected void configureField(Field<?> field) {
         super.configureField(field);
diff --git a/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java b/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java
new file mode 100644 (file)
index 0000000..68c1133
--- /dev/null
@@ -0,0 +1,41 @@
+package com.vaadin.tests.server.component.fieldgroup;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import com.vaadin.data.fieldgroup.BeanFieldGroup;
+
+public class BeanFieldGroupTest {
+
+    public static class MyBean {
+
+        private MyNestedBean nestedBean = new MyNestedBean();
+
+        public MyNestedBean getNestedBean() {
+            return nestedBean;
+        }
+    }
+
+    public static class MyNestedBean {
+
+        private String hello = "Hello world";
+
+        public String getHello() {
+            return hello;
+        }
+    }
+
+    @Test
+    public void buildAndBindNestedProperty() {
+
+        MyBean bean = new MyBean();
+
+        BeanFieldGroup<MyBean> bfg = new BeanFieldGroup<MyBean>(MyBean.class);
+        bfg.setItemDataSource(bean);
+
+        com.vaadin.ui.Field<?> helloField = bfg.buildAndBind("Hello string",
+                "nestedBean.hello");
+        assertEquals(bean.nestedBean.hello, helloField.getValue().toString());
+    }
+
+}