diff options
author | Artur Signell <artur@vaadin.com> | 2013-06-10 20:01:40 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-11 12:40:09 +0000 |
commit | 3d9d47d222a53e33267cb3f26112782fe9f12caf (patch) | |
tree | a8fdc3a5bcaecf535673f957f8ef1bb7254d1f73 /server/src/com/vaadin/ui | |
parent | 5793a1c3a2da2c9771bd1721483a4689100d4bc3 (diff) | |
download | vaadin-framework-3d9d47d222a53e33267cb3f26112782fe9f12caf.tar.gz vaadin-framework-3d9d47d222a53e33267cb3f26112782fe9f12caf.zip |
Added type parameter to converter methods (#11895)
Change-Id: I6562c537d9e5a0745eb67bc613123a265578ae00
Diffstat (limited to 'server/src/com/vaadin/ui')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractField.java | 28 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/Table.java | 3 |
2 files changed, 22 insertions, 9 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 7ac3a57c46..6a52d6b849 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -740,13 +740,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ private Object convertToModel(T fieldValue, Locale locale) throws Converter.ConversionException { - Class<?> modelType = null; - Property pd = getPropertyDataSource(); - if (pd != null) { - modelType = pd.getType(); - } else if (getConverter() != null) { - modelType = getConverter().getModelType(); - } + Class<?> modelType = getModelType(); try { return ConverterUtil.convertToModel(fieldValue, (Class<Object>) modelType, getConverter(), locale); @@ -756,6 +750,24 @@ public abstract class AbstractField<T> extends AbstractComponent implements } /** + * Retrieves the type of the currently used data model. If the field has no + * data source then the model type of the converter is used. + * + * @since 7.1 + * @return The type of the currently used data model or null if no data + * source or converter is set. + */ + protected Class<?> getModelType() { + Property<?> pd = getPropertyDataSource(); + if (pd != null) { + return pd.getType(); + } else if (getConverter() != null) { + return getConverter().getModelType(); + } + return null; + } + + /** * Returns the conversion error with {0} replaced by the data source type * and {1} replaced by the exception (localized) message. * @@ -935,7 +947,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements if (getConverter() != null) { try { valueToValidate = getConverter().convertToModel(fieldValue, - getLocale()); + getModelType(), getLocale()); } catch (ConversionException e) { throw new InvalidValueException(getConversionError( getConverter().getModelType(), e)); diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 3d7cb42050..a688b2eb45 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -4011,7 +4011,8 @@ public class Table extends AbstractSelect implements Action.Container, } Object value = property.getValue(); if (converter != null) { - return converter.convertToPresentation(value, getLocale()); + return converter.convertToPresentation(value, String.class, + getLocale()); } return (null != value) ? value.toString() : ""; } |