summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/main/java/com/vaadin/data/Binder.java8
-rw-r--r--server/src/test/java/com/vaadin/data/BinderTest.java19
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);