From 3d9d47d222a53e33267cb3f26112782fe9f12caf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Jun 2013 20:01:40 +0300 Subject: Added type parameter to converter methods (#11895) Change-Id: I6562c537d9e5a0745eb67bc613123a265578ae00 --- server/src/com/vaadin/ui/AbstractField.java | 28 ++++++++++++++++++++-------- server/src/com/vaadin/ui/Table.java | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'server/src/com/vaadin/ui') 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 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) modelType, getConverter(), locale); @@ -755,6 +749,24 @@ public abstract class AbstractField 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 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() : ""; } -- cgit v1.2.3