diff options
author | Artur Signell <artur@vaadin.com> | 2013-03-25 21:53:25 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-03-31 11:01:47 +0000 |
commit | af4fdcda594c392eb417dc6291fbb98fa6474a90 (patch) | |
tree | 0fc8cfb665a8836bf2baad65297a559321a537f5 /server/src | |
parent | 833b117b967e3466b37bf95d3f801e927e0e5c45 (diff) | |
download | vaadin-framework-af4fdcda594c392eb417dc6291fbb98fa6474a90.tar.gz vaadin-framework-af4fdcda594c392eb417dc6291fbb98fa6474a90.zip |
Convert value if locale changes and field has converter (#11419)
Change-Id: Icb33ee2db9e36d4282c19b46203054a2da4abdbd
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractField.java | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 619d717d97..4ec6d7bac2 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1321,15 +1321,33 @@ public abstract class AbstractField<T> extends AbstractComponent implements } private void localeMightHaveChanged() { - if (!equals(valueLocale, getLocale()) && dataSource != null - && !isModified()) { - // When we have a data source and the internal value is directly - // read from that we want to update the value - T newInternalValue = convertFromModel(getPropertyDataSource() - .getValue()); - if (!equals(newInternalValue, getInternalValue())) { - setInternalValue(newInternalValue); - fireValueChange(false); + if (!equals(valueLocale, getLocale())) { + // The locale HAS actually changed + + if (dataSource != null && !isModified()) { + // When we have a data source and the internal value is directly + // read from that we want to update the value + T newInternalValue = convertFromModel(getPropertyDataSource() + .getValue()); + if (!equals(newInternalValue, getInternalValue())) { + setInternalValue(newInternalValue); + fireValueChange(false); + } + } else if (dataSource == null && converter != null) { + /* + * No data source but a converter has been set. The same issues + * as above but we cannot use propertyDataSource. Convert the + * current value back to a model value using the old locale and + * then convert back using the new locale. If this does not + * match the field value we need to set the converted value + * again. + */ + Object convertedValue = convertToModel(getInternalValue(), + valueLocale); + T newinternalValue = convertFromModel(convertedValue); + if (!equals(getInternalValue(), newinternalValue)) { + setConvertedValue(convertedValue); + } } } } |