aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2014-09-13 22:46:28 +0300
committerVaadin Code Review <review@vaadin.com>2014-09-23 09:33:37 +0000
commit69df69f494244d6ce6e6c4e32ceea2c75767061f (patch)
tree9e1c9887212ed8f56180a2d86a971027ea130970
parent9d0812f7425deff6ee5437993e08eeab7d4a84a0 (diff)
downloadvaadin-framework-69df69f494244d6ce6e6c4e32ceea2c75767061f.tar.gz
vaadin-framework-69df69f494244d6ce6e6c4e32ceea2c75767061f.zip
Set internal value instead of converted value when locale has changed. (#14400)
Change-Id: I2440f6471b8bbb016497bf59cffd023b013460dd
-rw-r--r--server/src/com/vaadin/ui/AbstractField.java3
-rw-r--r--uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java56
-rw-r--r--uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java24
3 files changed, 82 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java
index 47ac953319..bb70c0c57b 100644
--- a/server/src/com/vaadin/ui/AbstractField.java
+++ b/server/src/com/vaadin/ui/AbstractField.java
@@ -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
index 0000000000..a1cabe914e
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java
@@ -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
index 0000000000..03f490c73c
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java
@@ -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