aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2021-10-27 13:18:46 +0300
committerGitHub <noreply@github.com>2021-10-27 13:18:46 +0300
commit51d403f07d33add4332ad97823218a1040422ac8 (patch)
tree62561e0ea42e3e2b7afdd6030f29fa49ef9f1e88 /server/src
parentc425e1baac2df7e596836e2bf20534b516f2579f (diff)
downloadvaadin-framework-51d403f07d33add4332ad97823218a1040422ac8.tar.gz
vaadin-framework-51d403f07d33add4332ad97823218a1040422ac8.zip
fix: Ensure that side effects of readBean does not set hasChanges true (#12455)
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main/java/com/vaadin/data/Binder.java2
-rw-r--r--server/src/test/java/com/vaadin/data/BinderTest.java22
2 files changed, 23 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 110e260b0c..e969a032f7 100644
--- a/server/src/main/java/com/vaadin/data/Binder.java
+++ b/server/src/main/java/com/vaadin/data/Binder.java
@@ -1891,7 +1891,6 @@ public class Binder<BEAN> implements Serializable {
if (bean == null) {
clearFields();
} else {
- changedBindings.clear();
getBindings().forEach(binding -> {
// Some bindings may have been removed from binder
// during readBean. We should skip those bindings to
@@ -1902,6 +1901,7 @@ public class Binder<BEAN> implements Serializable {
binding.initFieldValue(bean, false);
}
});
+ changedBindings.clear();
getValidationStatusHandler().statusChange(
BinderValidationStatus.createUnresolvedStatus(this));
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 fe529fa8f5..62ac93ce8e 100644
--- a/server/src/test/java/com/vaadin/data/BinderTest.java
+++ b/server/src/test/java/com/vaadin/data/BinderTest.java
@@ -1518,6 +1518,28 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> {
assertEquals(new Double(2000), item.getSalaryDouble());
}
+ // See: https://github.com/vaadin/framework/issues/9581
+ @Test
+ public void withConverter_hasChangesFalse() {
+ TextField nameField = new TextField();
+ nameField.setValue("");
+ TextField rentField = new TextField();
+ rentField.setValue("");
+ rentField.addValueChangeListener(event -> {
+ nameField.setValue("Name");
+ });
+ item.setRent(BigDecimal.valueOf(10));
+ binder.forField(nameField).bind(Person::getFirstName, Person::setFirstName);
+ binder.forField(rentField).withConverter(new EuroConverter(""))
+ .withNullRepresentation(BigDecimal.valueOf(0d))
+ .bind(Person::getRent, Person::setRent);
+ binder.readBean(item);
+
+ assertFalse(binder.hasChanges());
+ assertEquals("€ 10.00", rentField.getValue());
+ assertEquals("Name", nameField.getValue());
+ }
+
private TextField createNullAnd42RejectingFieldWithEmptyValue(
String emptyValue) {
return new TextField() {