diff options
-rw-r--r-- | server/src/com/vaadin/ui/AbstractField.java | 8 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java | 22 |
2 files changed, 28 insertions, 2 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 9cf72a36b3..4b1476db32 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1348,8 +1348,12 @@ public abstract class AbstractField<T> extends AbstractComponent implements && !isBuffered() && !isModified()) { // When we have a data source and the internal value is directly // read from that we want to update the value - Object modelValue = convertToModel(getInternalValue(), valueLocale); - setValue(convertFromModel(modelValue)); + T newInternalValue = convertFromModel(getPropertyDataSource() + .getValue()); + if (!equals(newInternalValue, getInternalValue())) { + setInternalValue(newInternalValue); + fireValueChange(false); + } } } diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java index 16c7c4060d..2f1b1f9dbc 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java @@ -26,6 +26,12 @@ public class AbstractFieldValueConversions extends TestCase { 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town", Country.FINLAND)); + /** + * Java uses a non-breaking space (ascii 160) instead of space when + * formatting + */ + private static final char FORMATTED_SPACE = 160; + public void testWithoutConversion() { TextField tf = new TextField(); tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, @@ -87,6 +93,22 @@ public class AbstractFieldValueConversions extends TestCase { assertEquals("42", tf.getValue()); } + public void testChangeReadOnlyFieldLocale() { + VaadinSession.setCurrent(new VaadinSession(null)); + + TextField tf = new TextField("salary"); + tf.setLocale(new Locale("en", "US")); + ObjectProperty<Integer> ds = new ObjectProperty<Integer>(123456789); + ds.setReadOnly(true); + 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 testBooleanNullConversion() { CheckBox cb = new CheckBox(); cb.setConverter(new Converter<Boolean, Boolean>() { |