diff options
author | Denis <denis@vaadin.com> | 2017-02-01 15:28:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-01 15:28:40 +0200 |
commit | 38b475330868d2d7b0d0b2da0a14be4040ca89ae (patch) | |
tree | 60b65819fec1931b9405dd1f7eb6943d68a34215 /server/src/main/java/com | |
parent | 07d56a9ca050d976dec4f598ed39471ae369c588 (diff) | |
download | vaadin-framework-38b475330868d2d7b0d0b2da0a14be4040ca89ae.tar.gz vaadin-framework-38b475330868d2d7b0d0b2da0a14be4040ca89ae.zip |
Introduce Binder.addFialdValueChangeListener (#8273)
Fixes #8273
Diffstat (limited to 'server/src/main/java/com')
-rw-r--r-- | server/src/main/java/com/vaadin/data/Binder.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index 4cbcd18eb1..f291c791b7 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -39,6 +39,7 @@ import java.util.stream.Stream; import com.googlecode.gentyref.GenericTypeReflector; import com.vaadin.annotations.PropertyId; import com.vaadin.data.HasValue.ValueChangeEvent; +import com.vaadin.data.HasValue.ValueChangeListener; import com.vaadin.data.converter.StringToIntegerConverter; import com.vaadin.data.validator.BeanValidator; import com.vaadin.event.EventRouter; @@ -928,6 +929,7 @@ public class Binder<BEAN> implements Serializable { binderValidationResults); getBinder().getValidationStatusHandler().statusChange(status); getBinder().fireStatusChangeEvent(status.hasErrors()); + getBinder().fireValueChangeEvent(event); } /** @@ -1735,6 +1737,29 @@ public class Binder<BEAN> implements Serializable { } /** + * Adds field value change listener to all the fields in the binder. + * <p> + * Added listener is notified every time whenever any bound field value is + * changed. The same functionality can be achieved by adding a + * {@link ValueChangeListener} to all fields in the {@link Binder}. + * <p> + * The listener is added to all fields regardless of whether the method is + * invoked before or after field is bound. + * + * @see ValueChangeEvent + * @see ValueChangeListener + * + * @param listener + * a field value change listener + * @return a registration for the listener + */ + public Registration addValueChangeListener( + ValueChangeListener<?> listener) { + return getEventRouter().addListener(ValueChangeEvent.class, listener, + ValueChangeListener.class.getDeclaredMethods()[0]); + } + + /** * Creates a new binding with the given field. * * @param <FIELDVALUE> @@ -2239,4 +2264,7 @@ public class Binder<BEAN> implements Serializable { return fieldName.toLowerCase(Locale.ENGLISH).replace("_", ""); } + private <V> void fireValueChangeEvent(ValueChangeEvent<V> event) { + getEventRouter().fireEvent(event); + } } |