Keep item selected after grid.refreashAll()

Hi, I use Vaadin 24 and I try to keep selection on item after refreshing grid items. Here is my not working code (item just deselects). I’m using single selection mode.

        conversationsGrid.addItemClickListener(conversation -> {
            //other logic
            conversationDataProvider.refreshAll();
            conversationsGrid.select(conversation.getItem());
        });```
How to keep it selected even after refreshing?

Get the selected items before refreshing and select them again. (Make sure the items have proper equals / hash code methods that return the same values before and after the refresh)

Equals and hash code methods seems to be working well (I use Lombok for them). With getting selected items still doesn’t work (I think it doesn’t matter if I use an item from event or from the getSelectedItems() method).

It doesn’t matter as long as the item’s equals and hash code method stays consistent in between refreshes. Not sure what you do, but Lombok implies by default that all properties of an object are used, so if the objects are different after the refresh, both won’t match anymore.

Okay I’ve found it. The problem was comparing empty lists inside objects. Inside the list’s type I didn’t override equals and hash code methods. Thanks