]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8102 getConvertedFieldValue -> getConvertedValue, added
authorArtur Signell <artur@vaadin.com>
Wed, 21 Dec 2011 17:00:02 +0000 (19:00 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 21 Dec 2011 17:00:02 +0000 (19:00 +0200)
setConvertedValue

src/com/vaadin/ui/AbstractField.java
tests/testbench/com/vaadin/tests/components/abstractfield/IntegerDoubleFieldsWithDataSource.java
tests/testbench/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java

index 5a8b9037e0138fb88c6c7fa3b4dfa40f2e685855..d6ce5450960e3232a401a54eb28c0e9434398f9e 100644 (file)
@@ -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 */
 
     /**
index d9a731ae4d2f648064e607ec415ee219d76082b9..d10b7140e1e8a7c8dec4a8fb7054cd4c39447a02 100644 (file)
@@ -38,7 +38,7 @@ public class IntegerDoubleFieldsWithDataSource extends TestBase {
                 try {\r
                     log.log("Value for " + tf.getCaption() + " changed to "\r
                             + tf.getValue());\r
-                    log.log("Converted value is " + tf.getConvertedFieldValue());\r
+                    log.log("Converted value is " + tf.getConvertedValue());\r
                 } catch (Exception e) {\r
                     // TODO: handle exception\r
                     e.printStackTrace();\r
index 8745df991a6674b4aac203dedc3ab6921a5cf28e..9d7edd38229adf39456385a6e8b4a23ef841488d 100644 (file)
@@ -2,7 +2,6 @@ package com.vaadin.tests.components.abstractfield;
 \r
 import com.vaadin.data.Property.ValueChangeEvent;\r
 import com.vaadin.data.Property.ValueChangeListener;\r
-import com.vaadin.data.util.converter.IntegerToStringConverter;\r
 import com.vaadin.tests.components.TestBase;\r
 import com.vaadin.tests.util.Log;\r
 import com.vaadin.ui.TextField;\r
@@ -34,7 +33,7 @@ public class IntegerFieldWithoutDataSource extends TestBase {
                 try {\r
                     log.log("Value for " + tf.getCaption() + " changed to "\r
                             + tf.getValue());\r
-                    log.log("Converted value is " + tf.getConvertedFieldValue());\r
+                    log.log("Converted value is " + tf.getConvertedValue());\r
                 } catch (Exception e) {\r
                     // TODO: handle exception\r
                     e.printStackTrace();\r