From 69df69f494244d6ce6e6c4e32ceea2c75767061f Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Sat, 13 Sep 2014 22:46:28 +0300 Subject: Set internal value instead of converted value when locale has changed. (#14400) Change-Id: I2440f6471b8bbb016497bf59cffd023b013460dd --- server/src/com/vaadin/ui/AbstractField.java | 3 +- .../textfield/LocaleChangeOnReadOnlyField.java | 56 ++++++++++++++++++++++ .../textfield/LocaleChangeOnReadOnlyFieldTest.java | 24 ++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyField.java create mode 100644 uitest/src/com/vaadin/tests/components/textfield/LocaleChangeOnReadOnlyFieldTest.java 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 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 -- cgit v1.2.3