Skip to content

Commit

Permalink
Remove removed binding from changedBinding field
Browse files Browse the repository at this point in the history
Fixes #5384
  • Loading branch information
Denis Anisimov committed Nov 3, 2019
1 parent eb4401b commit 0a74a6c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
10 changes: 7 additions & 3 deletions flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,11 @@ default BindingBuilder<BEAN, TARGET> withNullRepresentation(
TARGET nullRepresentation) {
return withConverter(
fieldValue -> Objects.equals(fieldValue, nullRepresentation)
? null : fieldValue,
? null
: fieldValue,
modelValue -> Objects.isNull(modelValue)
? nullRepresentation : modelValue);
? nullRepresentation
: modelValue);
}

/**
Expand Down Expand Up @@ -2503,7 +2505,8 @@ private <FIELDVALUE> Converter<FIELDVALUE, FIELDVALUE> createNullRepresentationA
Converter<FIELDVALUE, FIELDVALUE> nullRepresentationConverter = Converter
.from(fieldValue -> fieldValue,
modelValue -> Objects.isNull(modelValue)
? field.getEmptyValue() : modelValue,
? field.getEmptyValue()
: modelValue,
Throwable::getMessage);
ConverterDelegate<FIELDVALUE> converter = new ConverterDelegate<>(
nullRepresentationConverter);
Expand Down Expand Up @@ -2882,6 +2885,7 @@ protected void removeBindingInternal(Binding<BEAN, ?> binding) {
if (bindings.remove(binding)) {
boundProperties.entrySet()
.removeIf(entry -> entry.getValue().equals(binding));
changedBindings.remove(binding);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ public void bindNullBean_FieldsAreCleared() {
assertEquals("Age field not empty", "", ageField.getValue());
}

@Test
public void removeInvalidBinding_validateDoesNotThrow() {
binder.forField(nameField).bind(Person::getFirstName,
Person::setFirstName);
Binding<Person, Integer> ageBinding = binder.forField(ageField)
.withConverter(new StringToIntegerConverter(""))
.bind(Person::getAge, Person::setAge);
binder.withValidator(bean -> true, "");
binder.setBean(item);

ageField.setValue("foo");

binder.removeBinding(ageBinding);

binder.validate();
}

@Test
public void clearForReadBean_boundFieldsAreCleared() {
binder.forField(nameField).bind(Person::getFirstName,
Expand Down Expand Up @@ -451,8 +468,9 @@ public void beanBinder_withConverter_nullRepresentationIsNotDisabled() {
String customNullPointerRepresentation = "foo";
Binder<Person> binder = new Binder<>(Person.class);
binder.forField(nameField)
.withConverter(value -> value, value -> value == null
? customNullPointerRepresentation : value)
.withConverter(value -> value,
value -> value == null ? customNullPointerRepresentation
: value)
.bind("firstName");

Person person = new Person();
Expand Down Expand Up @@ -1345,7 +1363,6 @@ public void nullRejetingField_nullValue_wrappedExceptionMentionsNullRepresentati
binder.readBean(new AtomicReference<>());
}


@Test
public void nullRejetingField_otherRejectedValue_originalExceptionIsThrown() {
TestTextField field = createNullRejectingFieldWithEmptyValue("");
Expand Down

0 comments on commit 0a74a6c

Please sign in to comment.