ComboBox integer values in 7.4.0

Hi, I have the following problem, I have a combobox that you can select a year, (i.e. from 1920-2015), there was a simple for loop that would fill the combobox and then I would get the value.
In Vaadin 7.4.0 the numbers now are shown like this:
i.e. 1980 is now show 1,980
How do I remove the , from the number? (off course instead of integer I could have the year as a String, but that’s not the case. In 7.3.10 I had no problems.
Regards,
Nick

Hi, currently there is no ready-made configuration for this, but you can get around it by setting the caption separately with

combobox.setItemCaption(itemId, itemId.toString()); I made a
ticket
about the issue.

There seems to be another issue with ComboBoxes in 7.4.0 - calling setValue(Object) does not seem to work, at least I don’t see any selected values on the GUI. I can select one, but the default value which is set programmatically is missing.
Unfortunately I’m in the middle of some urgent work and therefore can’t dig deeper, so I went back to 7.3.10 and it works fine again.

That one I cannot reproduce. I tested with both Strings and custom Beans, and setValue(itemId) works just fine for me on 7.4.0. Are you using some non-default container that might affect the behaviour?

I just found out that binding the field to a FieldGroup causes the value not being displayed.

After looking into the source code of FieldGroup.bind() it becomes obvious: there is now a call to field.clear() (as I don’t use a DataSource).

Workaround would be to call setValue() after bind(), but it’s a bit unfortunate that there is change of behaviour in the new version.

Ah, yes, FieldGroup did get updated in such way. It’s generally a good idea to bind first and do all the settings later, but this change could have been communicated better in the release notes.

Hi, in this forum there already was posted another solution like this:

public class NonFormattingIntegerFormatter extends StringToIntegerConverter {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * @see com.vaadin.data.util.converter.StringToIntegerConverter#getFormat(java.util.Locale)
     */
    @Override
    protected NumberFormat getFormat(final Locale locale) {

        final NumberFormat format = super.getFormat(locale);
        format.setGroupingUsed(false);
        return format;
    }

}

Now you can set the converter to your Integer field. You have to do the same for Long converter if needed.

Credits to Marko Grönroos who has shown this solution (sorry, can’t find the post)

Oh sorry, this setConverter does not seem to have any effect :frowning:

First at all it is VERY ugly. I have a combobox with Integers and I have to create a Converter<Object, Integer>. Why object for presentation? I want to present String of course. This leads to very ugly casting.

Second: The convert convertToPresentation() method is being called and this doubleConvertedFieldValue is being set (in the method AbstractField#setValue() ???) but the presentation still is “2.015”. That’s laughable!

Thank you Anna for creating the ticket and showing the workaround.

I really don’t understand the logic behind com.vaadin.ui.AbstractSelect.idToCaption(Object). Why refuse to call super.getConverter()? The converter logic seems to be broken with all AbstractSelect fields :frowning: