diff options
author | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-04-11 12:07:29 +0000 |
---|---|---|
committer | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-04-11 12:07:29 +0000 |
commit | 812d41be428701e66fcafa3d20182fb11afc5f99 (patch) | |
tree | 49eab7921e380edd5e33a496e3e1ed41f4fcf5e0 | |
parent | 38cd0fd147868f3bec247a53b655104c9dd24120 (diff) | |
download | vaadin-framework-812d41be428701e66fcafa3d20182fb11afc5f99.tar.gz vaadin-framework-812d41be428701e66fcafa3d20182fb11afc5f99.zip |
#6155 Javadoc/comments; refresh field value from data source on attach
svn changeset:23476/svn branch:6.8
-rw-r--r-- | src/com/vaadin/ui/AbstractField.java | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index f3939de6e1..e1d3270225 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -140,9 +140,14 @@ public abstract class AbstractField extends AbstractComponent implements Field, private boolean valueWasModifiedByDataSourceDuringCommit; /** - * Whether this field currently listens to Property events. + * Whether this field is currently registered as listening to events from + * its data source. + * + * @see #setPropertyDataSource(Property) + * @see #addPropertyListeners() + * @see #removePropertyListeners() */ - private boolean isListening = false; + private boolean isListeningToPropertyEvents = false; /* Component basics */ @@ -582,6 +587,17 @@ public abstract class AbstractField extends AbstractComponent implements Field, * </p> * * <p> + * If the data source implements + * {@link com.vaadin.data.Property.ValueChangeNotifier} and/or + * {@link com.vaadin.data.Property.ReadOnlyStatusChangeNotifier}, the field + * registers itself as a listener and updates itself according to the events + * it receives. To avoid memory leaks caused by references to a field no + * longer in use, the listener registrations are removed on + * {@link AbstractField#detach() detach} and re-added on + * {@link AbstractField#attach() attach}. + * </p> + * + * <p> * Note: before 6.5 we actually called discard() method in the beginning of * the method. This was removed to simplify implementation, avoid excess * calls to backing property and to avoid odd value change events that were @@ -1120,8 +1136,14 @@ public abstract class AbstractField extends AbstractComponent implements Field, if (actionManager != null) { actionManager.setViewer(getWindow()); } - // No-op if listeners already registered - addPropertyListeners(); + + if (!isListeningToPropertyEvents) { + addPropertyListeners(); + if (!isModified() && isReadThrough()) { + // Update value from data source + discard(); + } + } } @Override @@ -1334,8 +1356,13 @@ public abstract class AbstractField extends AbstractComponent implements Field, } } + /** + * Registers this as an event listener for events sent by the data source + * (if any). Does nothing if + * <code>isListeningToPropertyEvents == true</code>. + */ private void addPropertyListeners() { - if (!isListening) { + if (!isListeningToPropertyEvents) { if (dataSource instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier) dataSource).addListener(this); } @@ -1343,12 +1370,16 @@ public abstract class AbstractField extends AbstractComponent implements Field, ((Property.ReadOnlyStatusChangeNotifier) dataSource) .addListener(this); } - isListening = true; + isListeningToPropertyEvents = true; } } + /** + * Stops listening to events sent by the data source (if any). Does nothing + * if <code>isListeningToPropertyEvents == false</code>. + */ private void removePropertyListeners() { - if (isListening) { + if (isListeningToPropertyEvents) { if (dataSource instanceof Property.ValueChangeNotifier) { ((Property.ValueChangeNotifier) dataSource) .removeListener(this); @@ -1357,7 +1388,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, ((Property.ReadOnlyStatusChangeNotifier) dataSource) .removeListener(this); } - isListening = false; + isListeningToPropertyEvents = false; } } }
\ No newline at end of file |