Vaadin 12 ItemLabelGenerator of ComboBox when used in grid-componentRendere

I have posted [this exact issue]
(https://stackoverflow.com/q/53668416/3441504) on stackoverflow, but there was no reaction so I’m posting it here too now. Of course I understand if you need time first to reproduce and check some stuff, I just want to make you guys aware of this issue.

Last week I have upgraded from Vaadin 11.0.2 to 12.0.0 - Everything went smooth, except one thing:
In a grid of mine where I have a rendered column to show a ComboBox, there is a strange issue with the ItemLabelGenerator. I defined it as follows:

grid.addColumn(new ComponentRenderer<>(gridItem -> {

    ComboBox<MyObject> comboBox = new ComboBox<>();
    comboBox.setItems(myObjectsService.findAll());
    comboBox.setValue(gridItem.getMyObject());
    comboBox.setItemLabelGenerator(MyObject::getName); // MyObject::getName returns String
    // comboBox.addValueChangeListener omitted
    return comboBox;

}))
    .setHeader("MyObject")
    .setId("myObject");

This has been working fine in Vaadin 11.0.2 but now the item-labels are displayed as package.path.to.myobject.MyObject@41d8d522 and not the actual name of gridItem.getMyObject();
When I click on the ComboBox to show all options, the labels are correct! but as soon as I select one, it turns into the aforementioned wrong string.

Important detail: for testing reasons I have now added a similar ComboBox with the same setup into a simple VerticalLayout (AKA not in a grid), and there everything works perfectly fine. That is why I think the issue is with the ComponentRenderer somehow and not with the ComboBox alone.

Is this a bug, or have I missed something when upgrading to 12.0.0 ?

In the [vaadin blog post about the new release of Vaadin 12]
(https://vaadin.com/blog/vaadin-12-brings-new-components-and-improved-performance), I see that there is one known breaking change, and it has to do with ComboBox:

If you are coming from Vaadin 10 or 11, you should update the platform dependency in your project build file. The only breaking change we introduced was because ComboBox now supports server-side lazy-loading. If you are using filtering with a ComboBox see instructions on fixing the possible compilation issue.

However, no filtering whatsoever is involved in my case.

Hello Kaspar,

I created an example similar to yours and I discover that the order in which you set the value and the ItemLabelGenerator matters.

You should put comboBox.setValue after setting the comboBox.setItemLabelGenerator.

Otherwise the method String.valueOf(obj) will be called the first time, giving you the object’s representation (MyObject@41d8d522) and not the name.

Diego Sanz Villafruela:
You should put comboBox.setValue after setting the comboBox.setItemLabelGenerator.

This indeed works, thank you for finding that.

I feel a little guilty for not trying that out myself, but then again - am I expected to know this? I think many more devs will step into this issue, because with Vaadin 11 it worked like that. I’m not saying that Vaadin 12 should behave exactly like Vaadin 11, but maybe some documentation where changes like this one are listed would be nice.

That’s definitely buggy behavior. Could you file a ticket at https://github.com/vaadin/vaadin-combo-box-flow/issues ?

-Olli

Thank you so much for reassuring that this is a bug and not a feature. I opened a ticket there now.