]> source.dussan.org Git - vaadin-framework.git/commitdiff
Set internal value instead of converted value when locale has changed. (#14400)
authorSauli Tähkäpää <sauli@vaadin.com>
Sat, 13 Sep 2014 19:46:28 +0000 (22:46 +0300)
committerSauli Tähkäpää <sauli@vaadin.com>
Wed, 24 Sep 2014 18:59:16 +0000 (21:59 +0300)
Change-Id: I2440f6471b8bbb016497bf59cffd023b013460dd

server/src/com/vaadin/ui/AbstractField.java
uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java [new file with mode: 0644]

index 47ac9533193fd3d02e44adbf38caabf675752f82..bb70c0c57bf354c0f6299e34d8260c95bb9df2a9 100644 (file)
@@ -1402,7 +1402,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements
                         valueLocale);
                 T newinternalValue = convertFromModel(convertedValue);
                 if (!SharedUtil.equals(getInternalValue(), newinternalValue)) {
-                    setConvertedValue(convertedValue);
+                    setInternalValue(newinternalValue);
+                    fireValueChange(false);
                 }
             }
         }
diff --git a/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java
new file mode 100644 (file)
index 0000000..a1cabe9
--- /dev/null
@@ -0,0 +1,56 @@
+package com.vaadin.tests.components.textfield;
+
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.TextField;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+
+public class LocaleChangeOnReadOnlyField extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        final TextField textField = getReadOnlyTextField();
+        addComponent(textField);
+
+        Button changeLocaleButton = addLocaleChangeButton(textField);
+        addComponent(changeLocaleButton);
+    }
+
+    private TextField getReadOnlyTextField() {
+        final TextField textField = new TextField();
+
+        textField.setConverter(BigDecimal.class);
+        textField.setLocale(Locale.US);
+        textField.setValue("1024000");
+        textField.setReadOnly(true);
+
+        return textField;
+    }
+
+    private Button addLocaleChangeButton(final TextField textField) {
+        Button changeLocaleButton = new Button();
+        changeLocaleButton.setCaption("Change Locale");
+        changeLocaleButton.addClickListener(new Button.ClickListener() {
+            @Override
+            public void buttonClick(Button.ClickEvent event) {
+                textField.setLocale(Locale.GERMANY);
+            }
+        });
+
+        return changeLocaleButton;
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Read-only fields throw exception when setting converted value in localeMightHaveChanged()";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 14400;
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java
new file mode 100644 (file)
index 0000000..03f490c
--- /dev/null
@@ -0,0 +1,24 @@
+package com.vaadin.tests.components.textfield;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class LocaleChangeOnReadOnlyFieldTest extends MultiBrowserTest {
+
+    @Test
+    public void localeIsChangedOnReadOnlyField() {
+        openTestURL();
+
+        TextFieldElement textField = $(TextFieldElement.class).first();
+        assertThat(textField.getValue(), is("1,024,000"));
+
+        $(ButtonElement.class).caption("Change Locale").first().click();
+        assertThat(textField.getValue(), is("1.024.000"));
+    }
+
+}
\ No newline at end of file