[Vaadin 8] setConverter is gone

I’m using setConverter extensively in my application, I have some custom components that extend vaadin’s ui components and I am setting the converters in my custom components.
With vaadin 8, setConverter method is gone, and the conversion happens on the level of the binder, this is completely different from vaadin 7 implementation because now it’s forcing us to identify the bean type beforehand which causes some coupling between the field and the bean.
In vaadin 7, the field is independant and the converter is set on it to allow any bean type to be used. Is there a way to set the converter on the field in vaadin 8 without using the binder?
May be I am missing something obvious but I am still learning vaadin 8 so any help will be appreciated.

In Vaadin 8 in most cases you do not need converter in same way as in Vaadin 7. As you have noticed in binder you can set converter, as in editor two way converter is needed. For simple case of rendering a value, only one way conversion is needed, which in Vaadin 8 can be implemented as follows: grid.addColumn(myPojo → (myPojo.isTruth() ? VaadinIcons.CHECK_CIRCLE : VaadinIcons.CIRCLE).getHtml(), new HtmlRenderer()).setCaption(“Truth”); The example assumes you have bean myPojo and the bean implements isTruth, getTruth in regualr manner. Br. Tatu
​​

Hello! I have a similar issue. With the following code it was possible to check within the converter whether the user entered a wrong format (or for example chars instead of digits). The content of the textfield was automatically replaced with for example the old value. Additional to this it was easy possible to automatically replace “5.2” to “5.20” for example. Is there an easy way to get this feature back without rewrite erverything? Thanks in advance!

public class PriceTextField extends TextField {
    
    public PriceTextField() {
        this.setConverter(new PriceConverter());
        this.setMaxLength(12);
    }
    
    public Price getPriceValue() {
        return (Price) getConvertedValue();
    }
    
    public void setPriceValue(Price value) {
        String formatedPrice = value.getFormatedPrice();
        super.setValue(formatedPrice);
    }
    
}

I read some documentation and checked some tutorials, but it seems that it is not possible to get the behaviour back as from Vaadin 7. Is this right?

Does anyone have an idea?:slight_smile:

Apparently that’s a vaadin 8 design decision and unfortunately there’s no way in vaadin 8 to achieve the same behavior as in vaadin 7.
There needs to be a binder to attach the bean to the converter.

Hello all! Thanks for the answer! I understand that I have to use the binder. My question is how can I reach the behaviour to habe an online convertation? This means for example, by typing in 3.5 the field is automatically updated to “3,50 €”. This was possible with the way described in vaadin 7. I also think there is a possibility to do it in vaadin 8 right? :slight_smile:

I found the same issue here: https://vaadin.com/forum#!/thread/15931682