Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove removed binding from changedBinding field #6827

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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