diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-03-19 18:57:26 +0200 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-03-19 18:57:26 +0200 |
commit | 5aa6433972b2b0980bcb9a658f28a72e426453f8 (patch) | |
tree | a3dc9d09627e082ee3cb99ab26567132419bff46 /server | |
parent | 81f81fa3c41f1fc97a14b7f8d91cf6ea29af572b (diff) | |
download | vaadin-framework-5aa6433972b2b0980bcb9a658f28a72e426453f8.tar.gz vaadin-framework-5aa6433972b2b0980bcb9a658f28a72e426453f8.zip |
Add missing null check to Binding (#10726)
* Add missing null check to Binding
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/data/Binder.java | 8 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/data/BinderTest.java | 19 |
2 files changed, 24 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index 406784fda4..769ca74bed 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -1139,9 +1139,11 @@ public class Binder<BEAN> implements Serializable { */ private void handleFieldValueChange( ValueChangeEvent<FIELDVALUE> event) { - // Inform binder of changes; if setBean: writeIfValid - getBinder().handleFieldValueChange(this, event); - getBinder().fireValueChangeEvent(event); + if (binder != null) { + // Inform binder of changes; if setBean: writeIfValid + getBinder().handleFieldValueChange(this, event); + getBinder().fireValueChangeEvent(event); + } } /** diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index 5988061cd5..abbbe541ae 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -812,6 +812,25 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { } @Test + public void remove_binding_fromFieldValueChangeListener() { + // Add listener before bind to make sure it will be executed first. + nameField.addValueChangeListener(e -> { + if (e.getValue() == "REMOVE") { + binder.removeBinding(nameField); + } + }); + + binder.bind(nameField, Person::getFirstName, Person::setFirstName); + + binder.setBean(item); + + nameField.setValue("REMOVE"); + + // Removed binding should not update bean. + assertNotEquals("REMOVE", item.getFirstName()); + } + + @Test public void beanvalidation_two_fields_not_equal() { TextField lastNameField = new TextField(); setBeanValidationFirstNameNotEqualsLastName(nameField, lastNameField); |