]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update buffered field value if it has not been changed (#8192) 31/531/1
authorArtur Signell <artur@vaadin.com>
Tue, 18 Dec 2012 14:45:45 +0000 (16:45 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 18 Dec 2012 14:45:45 +0000 (16:45 +0200)
Change-Id: I70501fe0813d014304fac71b6b80f94d0fdee9da

server/src/com/vaadin/ui/AbstractField.java
server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java

index 4b1476db329b07b401b70cc152c0eaa0cbad6f0f..59f11c5d5c6fdf12e9499f051909084804300b6e 100644 (file)
@@ -1345,7 +1345,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
 
     private void localeMightHaveChanged() {
         if (!equals(valueLocale, getLocale()) && dataSource != null
-                && !isBuffered() && !isModified()) {
+                && !isModified()) {
             // When we have a data source and the internal value is directly
             // read from that we want to update the value
             T newInternalValue = convertFromModel(getPropertyDataSource()
index 2f1b1f9dbc7b85f45073faeea8e91c530f37464b..cd77101ac397dad3048e1fd926a8f9a0d70d975a 100644 (file)
@@ -44,6 +44,41 @@ public class AbstractFieldValueConversions extends TestCase {
         assertEquals("abc", paulaBean.getFirstName());
     }
 
+    public void testNonmodifiedBufferedFieldConversion() {
+        VaadinSession.setCurrent(new VaadinSession(null));
+        TextField tf = new TextField("salary");
+        tf.setBuffered(true);
+        tf.setLocale(new Locale("en", "US"));
+        ObjectProperty<Integer> ds = new ObjectProperty<Integer>(123456789);
+        tf.setPropertyDataSource(ds);
+        assertEquals((Integer) 123456789, ds.getValue());
+        assertEquals("123,456,789", tf.getValue());
+        tf.setLocale(new Locale("fi", "FI"));
+        assertEquals((Integer) 123456789, ds.getValue());
+        assertEquals("123" + FORMATTED_SPACE + "456" + FORMATTED_SPACE + "789",
+                tf.getValue());
+
+    }
+
+    public void testModifiedBufferedFieldConversion() {
+        VaadinSession.setCurrent(new VaadinSession(null));
+        TextField tf = new TextField("salary");
+        tf.setBuffered(true);
+        tf.setLocale(new Locale("en", "US"));
+        ObjectProperty<Integer> ds = new ObjectProperty<Integer>(123456789);
+        tf.setPropertyDataSource(ds);
+        assertEquals((Integer) 123456789, ds.getValue());
+        assertEquals("123,456,789", tf.getValue());
+        tf.setValue("123,123");
+        assertEquals((Integer) 123456789, ds.getValue());
+        assertEquals("123,123", tf.getValue());
+
+        tf.setLocale(new Locale("fi", "FI"));
+        assertEquals((Integer) 123456789, ds.getValue());
+        // Value should not be updated when field is buffered
+        assertEquals("123,123", tf.getValue());
+    }
+
     public void testStringIdentityConversion() {
         TextField tf = new TextField();
         tf.setConverter(new Converter<String, String>() {