diff options
-rw-r--r-- | server/src/main/java/com/vaadin/data/Binder.java | 5 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/data/BinderTest.java | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index 676030ec22..1c6c4a4591 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -1561,7 +1561,10 @@ public class Binder<BEAN> implements Serializable { * Clear all the bound fields for this binder. */ private void clearFields() { - bindings.forEach(binding -> binding.getField().clear()); + bindings.forEach(binding -> { + binding.getField().clear(); + clearError(binding.getField()); + }); if (hasChanges()) { fireStatusChangeEvent(false); } diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index 89392be3e3..a521449c04 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -442,6 +442,26 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { } @Test + public void readNullBeanRemovesError() { + TextField textField = new TextField(); + binder.forField(textField).asRequired("foobar") + .bind(Person::getFirstName, Person::setFirstName); + Assert.assertTrue(textField.isRequiredIndicatorVisible()); + Assert.assertNull(textField.getErrorMessage()); + + binder.readBean(item); + Assert.assertNull(textField.getErrorMessage()); + + textField.setValue(textField.getEmptyValue()); + Assert.assertTrue(textField.isRequiredIndicatorVisible()); + Assert.assertNotNull(textField.getErrorMessage()); + + binder.readBean(null); + assertTrue(textField.isRequiredIndicatorVisible()); + Assert.assertNull(textField.getErrorMessage()); + } + + @Test public void setRequired_withErrorMessageProvider_fieldGetsRequiredIndicatorAndValidator() { TextField textField = new TextField(); textField.setLocale(Locale.CANADA); |