diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-11-21 17:05:05 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-11-21 20:25:39 +0200 |
commit | 5bc0a2f77183fcd0aaed8af7651fcbae553aeae9 (patch) | |
tree | 374cca0957a207dadf06140e1237a486f1219263 | |
parent | 9d804fa59513d64df15552e610b7a8b6516e8013 (diff) | |
download | vaadin-framework-8.2.0.beta1.tar.gz vaadin-framework-8.2.0.beta1.zip |
Improve Binder JavaDocs and APIs (#10347)8.2.0.beta1
This patch also adds ValueChangeEvent as a parameter to field value change method in Binder.
-rw-r--r-- | server/src/main/java/com/vaadin/data/Binder.java | 29 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/data/BinderTest.java | 8 |
2 files changed, 30 insertions, 7 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index 0fe357e368..a443421a0f 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -1078,7 +1078,7 @@ public class Binder<BEAN> implements Serializable { private void handleFieldValueChange( ValueChangeEvent<FIELDVALUE> event) { // Inform binder of changes; if setBean: writeIfValid - getBinder().handleFieldValueChange(this); + getBinder().handleFieldValueChange(this, event); getBinder().fireValueChangeEvent(event); } @@ -1246,9 +1246,12 @@ public class Binder<BEAN> implements Serializable { * * @param binding * the binding whose value has been changed + * @param event + * the value change event * @since 8.2 */ - protected void handleFieldValueChange(Binding<BEAN, ?> binding) { + protected void handleFieldValueChange(Binding<BEAN, ?> binding, + ValueChangeEvent<?> event) { changedBindings.add(binding); if (getBean() != null) { doWriteIfValid(getBean(), changedBindings); @@ -1692,7 +1695,9 @@ public class Binder<BEAN> implements Serializable { } /** - * Restores the state of the bean from the given values. + * Restores the state of the bean from the given values. This method is used + * together with {@link #getBeanState(Object, Collection)} to provide a way + * to revert changes in case the bean validation fails after save. * * @param bean * the bean @@ -1714,7 +1719,9 @@ public class Binder<BEAN> implements Serializable { } /** - * Stores the state of the given bean. + * Stores the state of the given bean. This method is used together with + * {@link #restoreBeanState(Object, Map)} to provide a way to revert changes + * in case the bean validation fails after save. * * @param bean * the bean to store the state of @@ -1842,8 +1849,8 @@ public class Binder<BEAN> implements Serializable { /** * Validates the values of all bound fields and returns the validation - * status. This method can skip firing the event, based on the given - * {@code boolean}. + * status. This method can fire validation status events. Firing the events + * depends on the given {@code boolean}. * * @param fireEvent * {@code true} to fire validation status events; {@code false} @@ -2683,9 +2690,17 @@ public class Binder<BEAN> implements Serializable { * the binding to remove * * @since 8.2 + * + * @throws IllegalArgumentException + * if the given Binding is not in this Binder */ - public void removeBinding(Binding<BEAN, ?> binding) { + public void removeBinding(Binding<BEAN, ?> binding) + throws IllegalArgumentException { Objects.requireNonNull(binding, "Binding can not be null"); + if (!bindings.contains(binding)) { + throw new IllegalArgumentException( + "Provided Binding is not in this Binder"); + } binding.unbind(); } diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index b3bce11e87..36301afcfa 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -1011,4 +1011,12 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { assertEquals("Name should be read again from the item", item.getFirstName(), nameField.getValue()); } + + @Test(expected = IllegalArgumentException.class) + public void remove_binding_from_different_binder() { + Binder<Person> anotherBinder = new Binder<>(); + Binding<Person, String> binding = anotherBinder.bind(nameField, + Person::getFirstName, Person::setFirstName); + binder.removeBinding(binding); + } } |