Vaadin 8: where has Grid.Column.setConverter() gone?

I need to display and edit numbers with a fixed number of decimals in a grid (and elsewhere). A localized number field would be nice, but I digress.

For the purpose of editing in place, I had to write a converter, which is fine. I want numbers to look the same whether in the grid or during editing. The display of the grid itself does not use the editor converter, and there is no way that I can find to rely on
setConverter() as used to be possible in v7
(click on the link!). Since I already have the converter, and this used to work, maybe I’m just missing something silly.

        TextField bodyWeightField = new TextField();
        StringToBodyWeightConverter bodyWeightConverter = new StringToBodyWeightConverter(null, "not a number");
        Column<WeighInAthlete, Float> bwColumn = grid.addColumn(WeighInAthlete::getBodyWeight);
        bwColumn
            .setCaption("Body Weight")
            .setEditorBinding(
                binder.forField(bodyWeightField).withConverter(bodyWeightConverter)
                .bind(WeighInAthlete::getBodyWeight, WeighInAthlete::setBodyWeight));

The method addColumn in new Vaadin 8 Grid is overloaded with four altenatives. It is possible to give Renverer and ValueProvider as a parameter.

Ok, but it seems extremely error-prone to have to do as in the following code where I pass a NumberRenderer and still need a converter for editing. If I was able to pass my converter to the column, as used to be possible, I would be guaranteed that the editing and displaying behaviour were the same. Or maybe there is a trick for editing that does not require the converter ?

        TextField bodyWeightField = new TextField();
        StringToBodyWeightConverter bodyWeightConverter = new StringToBodyWeightConverter(null, "not a number");
        Column<WeighInAthlete, Float> bwColumn = grid.addColumn(WeighInAthlete::getBodyWeight, new NumberRenderer("0.00", UI.getCurrent().getLocale(), "-"));
        bwColumn
            .setCaption("Body Weight")
            .setEditorBinding(
                binder
                    .forField(bodyWeightField)
                    .withConverter(bodyWeightConverter)
                    .bind(WeighInAthlete::getBodyWeight, WeighInAthlete::setBodyWeight));
StringToBodyWeightConverter bodyWeightConverter = new StringToBodyWeightConverter(null, "not a number");
grid.addColumn(w -> bodyWeightConverter.convertToPresentation(w.getBodyWeight(), String.class, UI.getCurrent().getLocale())).setCaption("Body Weight");

In my project, I need to format my value in html. I have no way to sort the value if I use “addColumn(ValueProvider” to
format the value because I don’t want to sort on html code!

You can set a custom comparator in this case with setComparator method from Grid.Column class;

addColumn(myValueProvider).setComparator((d1, d2) → d1.getName().compareTo(d2.getName());

It’s the same problem.

I have a class named MyClass with an HtmlProvider. (In the example below, myClass1 is an instance object of MyClass class)

To have the html respresentation, I need to call “HtmlProvider.get(myClass1)”
If I do addColumn(myClass1 → HtmlProvider.get(myClass1)).setComparator((d1, d2) →

=> The d1 and d2 variables of comparator are the html produced by htmlProvider instead of MyClass instances and I need to compare the objects, not the htmls!

Perhaps the support for a separate presentation ValueProvider in Vaadin Framework 8.1 would help. This way, the internal reprensentation (from converters or such) can be suitable for internal use including comparison, and the presentation for renderers (e.g. HTML) can be generated separately from it.

FYI
I opened a ticket to allow setting/changing the value provider after column creation:
https://github.com/vaadin/framework/issues/9280

@Henri Sara
I don’t have the problem anymore since I migrated to the Vaadin 8.1 because we can now provide a ValueProvider + PresentationProvider
=> Grid.addColumn(ValueProvider<T, V> valueProvider, ValueProvider<V, String> presentationProvider)

For my part, the problem is solved

Thanks,