summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/data/fieldgroup/FieldGroup.java13
-rw-r--r--server/tests/src/com/vaadin/data/fieldgroup/FieldGroupTests.java47
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 <T> Property.Transactional<T> wrapInTransactionalProperty(
+ Property<T> itemProperty) {
+ return new TransactionalPropertyWrapper<T>(itemProperty);
+ }
+
private void throwIfFieldIsNull(Field<?> field, Object propertyId) {
if (field == null) {
throw new BindException(
@@ -283,11 +291,6 @@ public class FieldGroup implements Serializable {
}
}
- private <T> Property.Transactional<T> wrapInTransactionalProperty(
- Property<T> itemProperty) {
- return new TransactionalPropertyWrapper<T>(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 <T> Transactional<T> wrapInTransactionalProperty(
+ Property<T> itemProperty) {
+ return new TransactionalPropertyImpl(itemProperty);
+ }
+ };
+ group.setItemDataSource(new BeanItem<Bean>(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<T> extends
+ TransactionalPropertyWrapper<T> {
+
+ public TransactionalPropertyImpl(Property<T> wrappedProperty) {
+ super(wrappedProperty);
+ }
+
+ }
+
+ public static class Bean {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
}