diff options
author | Artur Signell <artur@vaadin.com> | 2013-03-25 21:53:25 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-03-31 11:01:47 +0000 |
commit | af4fdcda594c392eb417dc6291fbb98fa6474a90 (patch) | |
tree | 0fc8cfb665a8836bf2baad65297a559321a537f5 /server/tests | |
parent | 833b117b967e3466b37bf95d3f801e927e0e5c45 (diff) | |
download | vaadin-framework-af4fdcda594c392eb417dc6291fbb98fa6474a90.tar.gz vaadin-framework-af4fdcda594c392eb417dc6291fbb98fa6474a90.zip |
Convert value if locale changes and field has converter (#11419)
Change-Id: Icb33ee2db9e36d4282c19b46203054a2da4abdbd
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java b/server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java new file mode 100644 index 0000000000..9810873f0b --- /dev/null +++ b/server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java @@ -0,0 +1,63 @@ +package com.vaadin.ui; + +import java.text.NumberFormat; +import java.util.Locale; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.data.util.converter.StringToIntegerConverter; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinSession; + +public class AbstractFieldDataSourceLocaleChange { + + private VaadinSession vaadinSession; + private UI ui; + + @Before + public void setup() { + vaadinSession = new VaadinSession(null); + VaadinSession.setCurrent(vaadinSession); + ui = new UI() { + + @Override + protected void init(VaadinRequest request) { + + } + }; + ui.setSession(vaadinSession); + UI.setCurrent(ui); + } + + @Test + public void localeChangesOnAttach() { + TextField tf = new TextField(); + + ; + tf.setConverter(new StringToIntegerConverter() { + @Override + protected NumberFormat getFormat(Locale locale) { + if (locale == null) { + NumberFormat format = super.getFormat(locale); + format.setGroupingUsed(false); + format.setMinimumIntegerDigits(10); + return format; + } + return super.getFormat(locale); + } + }); + tf.setImmediate(true); + tf.setConvertedValue(10000); + Assert.assertEquals("0000010000", tf.getValue()); + + VerticalLayout vl = new VerticalLayout(); + ui.setContent(vl); + ui.setLocale(new Locale("en", "US")); + + vl.addComponent(tf); + Assert.assertEquals("10,000", tf.getValue()); + } +} |