Converters for Text/DateFields in Vaadin8

Hi,

in Vaadin 7 I used to extend a TextField, then I would call .setConverter() and I would attach a customized converter to be able to input customized values in text/date fields.

It appears this can’t be done anymore in Vaadin 8. A Converter class is still there (although changed significantly from the previous version), but there’s no .setConverter() method in Text/DateField.

Any suggestions please?

Thanks a lot,
Marco

This is one of the API structure changes between Vaadin 7 and Vaadin 8. In Vaadin 8, the converter is set with Binder, using withConverter(…) fluent API, see https://vaadin.com/api/8.0.6/com/vaadin/data/Binder.BindingBuilder.html

Thank you so much for your help, I’m going to study a lot about that… :slight_smile:

Marco

I began studying and implementing String<->BigDecimal conversions, using a class of mine which extends StringToBigDecimalConverter.

Everything works fine: convertToPresentation() and convertToModel() are called and they work properly.

However I don’t know how to format the text entered by the user on value changes, i.e.:

  • my custom converter is set to use #,##0.00 as number format;
  • the user enters “7”;
  • I can see the convertToModel() call and the conversion being run;
  • but the TextField still shows “7” instead of “7,00” (Italian locale).

requestRepaint() is not helpful.

In other words: how can I force the TextField to run a convertToPresentation() after a convertToModel()?

Thanks a lot,
Marco

I left the Binder way and I decided to simply extend the TextField class and override the doSetValue() method.

I’m posting the full code in a separate post, just in case someone needs it…

Thanks,
Marco

Hi Marco,

may i know your posting address?

Thaks a lot,
Irma

Hi Irma,

https://vaadin.com/forum/#!/thread/16153583

However, as noted, that code should be more “Vaadin 8.1” styled and maybe converted to an add-on…
Still, it works.

Thanks,
MZ

Hi Marco,

it was very helpful. thank you so much

Irma