From a17dd65572efed55f475a83871de112d978ed99f Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Wed, 29 Aug 2012 13:10:02 +0000 Subject: 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 --- src/com/vaadin/ui/AbstractField.java | 91 +++++++++++++++++++----------------- 1 file 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 -- cgit v1.2.3