From 18be259375c876963da86f3b83c72adfbda45fe1 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 9 Dec 2014 21:18:50 +0200 Subject: Make addNestedContainerBean work with existing bean item container items (#15355) Change-Id: I04a91349fce452aa26c304413061440ad74465cc --- .../vaadin/data/util/AbstractBeanContainer.java | 2 +- .../vaadin/data/util/BeanItemContainerTest.java | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/server/src/com/vaadin/data/util/AbstractBeanContainer.java b/server/src/com/vaadin/data/util/AbstractBeanContainer.java index 7d7d71c423..fad0934e53 100644 --- a/server/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/server/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -880,7 +880,7 @@ public abstract class AbstractBeanContainer extends model.put(qualifiedPropertyId, pd); model.remove(propertyId); for (BeanItem item : itemIdToItem.values()) { - item.addItemProperty(propertyId, + item.addItemProperty(qualifiedPropertyId, pd.createProperty(item.getBean())); item.removeItemProperty(propertyId); } diff --git a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java index 01c282e294..514bf70416 100644 --- a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java +++ b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java @@ -12,6 +12,7 @@ import org.junit.Assert; import com.vaadin.data.Container; import com.vaadin.data.Item; +import com.vaadin.data.util.NestedMethodPropertyTest.Address; /** * Test basic functionality of BeanItemContainer. @@ -740,4 +741,45 @@ public class BeanItemContainerTest extends AbstractBeanContainerTest { assertNull(container.getContainerProperty(john, "address.street") .getValue()); } + + public void testAddNestedContainerBeanBeforeData() { + BeanItemContainer container = new BeanItemContainer( + NestedMethodPropertyTest.Person.class); + + container.addNestedContainerBean("address"); + + assertTrue(container.getContainerPropertyIds().contains( + "address.street")); + + NestedMethodPropertyTest.Person john = new NestedMethodPropertyTest.Person( + "John", new Address("streetname", 12345)); + container.addBean(john); + + assertTrue(container.getItem(john).getItemPropertyIds() + .contains("address.street")); + assertEquals("streetname", + container.getItem(john).getItemProperty("address.street") + .getValue()); + + } + + public void testAddNestedContainerBeanAfterData() { + BeanItemContainer container = new BeanItemContainer( + NestedMethodPropertyTest.Person.class); + + NestedMethodPropertyTest.Person john = new NestedMethodPropertyTest.Person( + "John", new Address("streetname", 12345)); + container.addBean(john); + + container.addNestedContainerBean("address"); + + assertTrue(container.getContainerPropertyIds().contains( + "address.street")); + assertTrue(container.getItem(john).getItemPropertyIds() + .contains("address.street")); + assertEquals("streetname", + container.getItem(john).getItemProperty("address.street") + .getValue()); + + } } -- cgit v1.2.3