From: Artur Signell Date: Wed, 21 Dec 2011 17:00:02 +0000 (+0200) Subject: #8102 getConvertedFieldValue -> getConvertedValue, added X-Git-Tag: 7.0.0.alpha2~545^2~1^2~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e820369a8d001ff5d8b903f9978890cab28be81e;p=vaadin-framework.git #8102 getConvertedFieldValue -> getConvertedValue, added setConvertedValue --- diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 5a8b9037e0..d6ce545096 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -255,7 +255,7 @@ public abstract class AbstractField extends AbstractComponent implements // Commits the value to datasource. valueWasModifiedByDataSourceDuringCommit = false; committingValueToDataSource = true; - getPropertyDataSource().setValue(getConvertedFieldValue()); + getPropertyDataSource().setValue(getConvertedValue()); } catch (final Throwable e) { // Sets the buffering state. @@ -532,8 +532,10 @@ public abstract class AbstractField extends AbstractComponent implements *

* Note that the object returned is compatible with getType(). For example, * if the type is String, this returns Strings even when the underlying - * datasource is of some other type. In order to access the native value of - * the datasource, use getDataSourceValue() instead. + * datasource is of some other type. In order to access the converted value, + * use {@link #getConvertedValue()} and to access the value of the property + * data source, use {@link Property#getValue()} for the property data + * source. *

* *

@@ -898,13 +900,30 @@ public abstract class AbstractField extends AbstractComponent implements /** * Returns the current field value converted to the data source type. + *

+ * This returns the same as {@link AbstractField#getValue()} if no converter + * has been set. + *

* * @return The converted value that is compatible with the data source type */ - public Object getConvertedFieldValue() { + public Object getConvertedValue() { return convertToDataSource(getFieldValue()); } + /** + * Sets the value of the field using a value of the data source type. The + * value given is converted to the field type and then assigned to the + * field. This will update the property data source in the same way as when + * {@link #setValue(Object)} is called. + * + * @param value + * The value to set. Must be the same type as the data source. + */ + public void setConvertedValue(Object value) { + setValue(convertFromDataSource(value)); + } + /* Validation */ /** diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerDoubleFieldsWithDataSource.java b/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerDoubleFieldsWithDataSource.java index d9a731ae4d..d10b7140e1 100644 --- a/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerDoubleFieldsWithDataSource.java +++ b/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerDoubleFieldsWithDataSource.java @@ -38,7 +38,7 @@ public class IntegerDoubleFieldsWithDataSource extends TestBase { try { log.log("Value for " + tf.getCaption() + " changed to " + tf.getValue()); - log.log("Converted value is " + tf.getConvertedFieldValue()); + log.log("Converted value is " + tf.getConvertedValue()); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); diff --git a/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java b/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java index 8745df991a..9d7edd3822 100644 --- a/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java +++ b/tests/testbench/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java @@ -2,7 +2,6 @@ package com.vaadin.tests.components.abstractfield; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; -import com.vaadin.data.util.converter.IntegerToStringConverter; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.Log; import com.vaadin.ui.TextField; @@ -34,7 +33,7 @@ public class IntegerFieldWithoutDataSource extends TestBase { try { log.log("Value for " + tf.getCaption() + " changed to " + tf.getValue()); - log.log("Converted value is " + tf.getConvertedFieldValue()); + log.log("Converted value is " + tf.getConvertedValue()); } catch (Exception e) { // TODO: handle exception e.printStackTrace();