diff options
author | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-08-29 13:10:02 +0000 |
---|---|---|
committer | Johannes Dahlström <johannes.dahlstrom@vaadin.com> | 2012-08-29 13:10:02 +0000 |
commit | a17dd65572efed55f475a83871de112d978ed99f (patch) | |
tree | f9957d70195f34e12a6b97e375dc2365ac4bbf60 | |
parent | 41e56e93ce3d03cec7b904cbd3e2d7ea2f7597da (diff) | |
download | vaadin-framework-a17dd65572efed55f475a83871de112d978ed99f.tar.gz vaadin-framework-a17dd65572efed55f475a83871de112d978ed99f.zip |
Refactor discard() contents into a private helper so that overridden versions are not unexpectedly called in attach() (#9181)
svn changeset:24245/svn branch:6.8
-rw-r--r-- | src/com/vaadin/ui/AbstractField.java | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index e1d3270225..a3f46cd39a 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -301,47 +301,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, * we use the default documentation from the implemented interface. */ public void discard() throws Buffered.SourceException { - if (dataSource != null) { - - // Gets the correct value from datasource - Object newValue; - try { - - // Discards buffer by overwriting from datasource - newValue = String.class == getType() ? dataSource.toString() - : dataSource.getValue(); - - // If successful, remove set the buffering state to be ok - if (currentBufferedSourceException != null) { - currentBufferedSourceException = null; - requestRepaint(); - } - } catch (final Throwable e) { - - // Sets the buffering state - currentBufferedSourceException = new Buffered.SourceException( - this, e); - requestRepaint(); - - // Throws the source exception - throw currentBufferedSourceException; - } - - final boolean wasModified = isModified(); - modified = false; - - // If the new value differs from the previous one - if ((newValue == null && value != null) - || (newValue != null && !newValue.equals(value))) { - setInternalValue(newValue); - fireValueChange(false); - } - - // If the value did not change, but the modification status did - else if (wasModified) { - requestRepaint(); - } - } + updateValueFromDataSource(); } /* @@ -1140,8 +1100,9 @@ public abstract class AbstractField extends AbstractComponent implements Field, if (!isListeningToPropertyEvents) { addPropertyListeners(); if (!isModified() && isReadThrough()) { - // Update value from data source - discard(); + // The property value may have changed while the field was + // detached and not listening + updateValueFromDataSource(); } } } @@ -1356,6 +1317,50 @@ public abstract class AbstractField extends AbstractComponent implements Field, } } + private void updateValueFromDataSource() { + if (dataSource != null) { + + // Gets the correct value from datasource + Object newValue; + try { + + // Discards buffer by overwriting from datasource + newValue = String.class == getType() ? dataSource.toString() + : dataSource.getValue(); + + // If successful, remove set the buffering state to be ok + if (currentBufferedSourceException != null) { + currentBufferedSourceException = null; + requestRepaint(); + } + } catch (final Throwable e) { + + // Sets the buffering state + currentBufferedSourceException = new Buffered.SourceException( + this, e); + requestRepaint(); + + // Throws the source exception + throw currentBufferedSourceException; + } + + final boolean wasModified = isModified(); + modified = false; + + // If the new value differs from the previous one + if ((newValue == null && value != null) + || (newValue != null && !newValue.equals(value))) { + setInternalValue(newValue); + fireValueChange(false); + } + + // If the value did not change, but the modification status did + else if (wasModified) { + requestRepaint(); + } + } + } + /** * Registers this as an event listener for events sent by the data source * (if any). Does nothing if |