From 7cd562df674a9855d0a757f29518405e834c8037 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Thu, 8 Jan 2015 17:59:21 +0200 Subject: Allow to override transactional property wrapper strategy (#13883). Change-Id: I38acc3c6cfbe66ac9e9ce246accbb9a0b058dddb --- .../src/com/vaadin/data/fieldgroup/FieldGroup.java | 13 +++--- .../vaadin/data/fieldgroup/FieldGroupTests.java | 47 ++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java index a8cabc5887..4790d786e7 100644 --- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java @@ -266,6 +266,14 @@ public class FieldGroup implements Serializable { configureField(field); } + /** + * Wrap property to transactional property. + */ + protected Property.Transactional wrapInTransactionalProperty( + Property itemProperty) { + return new TransactionalPropertyWrapper(itemProperty); + } + private void throwIfFieldIsNull(Field field, Object propertyId) { if (field == null) { throw new BindException( @@ -283,11 +291,6 @@ public class FieldGroup implements Serializable { } } - private Property.Transactional wrapInTransactionalProperty( - Property itemProperty) { - return new TransactionalPropertyWrapper(itemProperty); - } - /** * Gets the property with the given property id from the item. * diff --git a/server/tests/src/com/vaadin/data/fieldgroup/FieldGroupTests.java b/server/tests/src/com/vaadin/data/fieldgroup/FieldGroupTests.java index eb8f21c839..fc267fc7da 100644 --- a/server/tests/src/com/vaadin/data/fieldgroup/FieldGroupTests.java +++ b/server/tests/src/com/vaadin/data/fieldgroup/FieldGroupTests.java @@ -4,10 +4,16 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.mockito.Mockito.mock; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.vaadin.data.Property; +import com.vaadin.data.Property.Transactional; +import com.vaadin.data.util.BeanItem; +import com.vaadin.data.util.TransactionalPropertyWrapper; import com.vaadin.ui.Field; +import com.vaadin.ui.TextField; public class FieldGroupTests { @@ -37,4 +43,45 @@ public class FieldGroupTests { public void cannotBindNullField() { sut.bind(null, "foobar"); } + + @Test + public void wrapInTransactionalProperty_provideCustomImpl_customTransactionalWrapperIsUsed() { + Bean bean = new Bean(); + FieldGroup group = new FieldGroup() { + @Override + protected Transactional wrapInTransactionalProperty( + Property itemProperty) { + return new TransactionalPropertyImpl(itemProperty); + } + }; + group.setItemDataSource(new BeanItem(bean)); + TextField field = new TextField(); + group.bind(field, "name"); + + Property propertyDataSource = field.getPropertyDataSource(); + Assert.assertTrue("Custom implementation of transactional property " + + "has not been used", + propertyDataSource instanceof TransactionalPropertyImpl); + } + + public static class TransactionalPropertyImpl extends + TransactionalPropertyWrapper { + + public TransactionalPropertyImpl(Property wrappedProperty) { + super(wrappedProperty); + } + + } + + public static class Bean { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } } -- cgit v1.2.3