aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2011-12-21 19:00:02 +0200
committerJens Jansson <peppe@vaadin.com>2011-12-22 09:53:12 +0200
commite820369a8d001ff5d8b903f9978890cab28be81e (patch)
tree80740c6c29c871b35da08b4bea3723dc61912698
parenta1324b394264973952223dfe3f49a1664d15a950 (diff)
downloadvaadin-framework-e820369a8d001ff5d8b903f9978890cab28be81e.tar.gz
vaadin-framework-e820369a8d001ff5d8b903f9978890cab28be81e.zip
#8102 getConvertedFieldValue -> getConvertedValue, added
setConvertedValue
-rw-r--r--src/com/vaadin/ui/AbstractField.java27
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/IntegerDoubleFieldsWithDataSource.java2
-rw-r--r--tests/testbench/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java3
3 files changed, 25 insertions, 7 deletions
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<T> 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<T> extends AbstractComponent implements
* <p>
* 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.
* </p>
*
* <p>
@@ -898,13 +900,30 @@ public abstract class AbstractField<T> extends AbstractComponent implements
/**
* Returns the current field value converted to the data source type.
+ * <p>
+ * This returns the same as {@link AbstractField#getValue()} if no converter
+ * has been set.
+ * </p>
*
* @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();