diff options
author | Artur Signell <artur@vaadin.com> | 2014-12-09 19:43:06 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-12-11 07:04:45 +0000 |
commit | b91063f884108bfc69a617846d91263339b062fe (patch) | |
tree | 637ef197b4c18d5061b0890149ab53f44f3ff4e7 /server/src | |
parent | 23bdb6e90d970bd4e9ef11c79c095e65b6963414 (diff) | |
download | vaadin-framework-b91063f884108bfc69a617846d91263339b062fe.tar.gz vaadin-framework-b91063f884108bfc69a617846d91263339b062fe.zip |
Clear all bound fields when nulling the field group data source (#12371)
Change-Id: I48eb0e7851187fa6bbb9024730b2611a74501ad0
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java | 9 | ||||
-rw-r--r-- | server/src/com/vaadin/data/fieldgroup/FieldGroup.java | 19 |
2 files changed, 19 insertions, 9 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java index 1f3ee36d58..257a958f3a 100644 --- a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java @@ -125,12 +125,19 @@ public class BeanFieldGroup<T> extends FieldGroup { * Helper method for setting the data source directly using a bean. This * method wraps the bean in a {@link BeanItem} and calls * {@link #setItemDataSource(Item)}. + * <p> + * For null values, a null item is passed to + * {@link #setItemDataSource(Item)} to be properly clear fields. * * @param bean * The bean to use as data source. */ public void setItemDataSource(T bean) { - setItemDataSource(new BeanItem<T>(bean, beanType)); + if (bean == null) { + setItemDataSource((Item) null); + } else { + setItemDataSource(new BeanItem<T>(bean, beanType)); + } } @Override diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java index bcfa8395df..c89b94ace9 100644 --- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java @@ -26,7 +26,6 @@ import java.util.List; import com.vaadin.data.Item; import com.vaadin.data.Property; -import com.vaadin.data.Validator; import com.vaadin.data.Validator.InvalidValueException; import com.vaadin.data.util.TransactionalPropertyWrapper; import com.vaadin.ui.AbstractField; @@ -256,6 +255,9 @@ public class FieldGroup implements Serializable { fieldToPropertyId.put(field, propertyId); propertyIdToField.put(propertyId, field); if (itemDataSource == null) { + // Clear any possible existing binding to clear the field + field.setPropertyDataSource(null); + field.clear(); // Will be bound when data source is set return; } @@ -461,7 +463,7 @@ public class FieldGroup implements Serializable { List<InvalidValueException> invalidValueExceptions = commitFields(); - if(invalidValueExceptions.isEmpty()) { + if (invalidValueExceptions.isEmpty()) { firePostCommitEvent(); commitTransactions(); } else { @@ -489,12 +491,14 @@ public class FieldGroup implements Serializable { return invalidValueExceptions; } - private void throwInvalidValueException(List<InvalidValueException> invalidValueExceptions) { - if(invalidValueExceptions.size() == 1) { + private void throwInvalidValueException( + List<InvalidValueException> invalidValueExceptions) { + if (invalidValueExceptions.size() == 1) { throw invalidValueExceptions.get(0); } else { - InvalidValueException[] causes = invalidValueExceptions.toArray( - new InvalidValueException[invalidValueExceptions.size()]); + InvalidValueException[] causes = invalidValueExceptions + .toArray(new InvalidValueException[invalidValueExceptions + .size()]); throw new InvalidValueException(null, causes); } @@ -515,8 +519,7 @@ public class FieldGroup implements Serializable { private void commitTransactions() { for (Field<?> f : fieldToPropertyId.keySet()) { - ((Property.Transactional<?>) f.getPropertyDataSource()) - .commit(); + ((Property.Transactional<?>) f.getPropertyDataSource()).commit(); } } |