Understanding VirtualList with KeyMapper

Using: 23.3.4
Related to: new VirtualList().getDataCommunicator().getKeyMapper().setIdentifierGetter(Entity::getId)

We do have two questions related to the keymapper in a virtual list:

  1. Our goal is to refresh a single item in a virtual list by the dataprovider, but it didn’t work by now. The method “refreshAll” works with no issue.
    We already use the equals method for a complete comparison for the whole entitie’s attributes, so we don’t like to change the implementation of this method.
    So we found the method setIdentifierGetter as written above and thought this may help us, comparing only the id’s of our entities. Is that the way how to do it, or might there be a better one?

  2. As we were testing our approach we were not sure whether the method is provided for us as developers or whether it’s targeting only internal use. If the method is provided for us as developers, too, please provide information about how to use the method properly.

Best, Silvan and Simon

Our workaround would be to create a custom DataProvider (CustomListDataProvider) and overwrite the getId method - that’s tested and works.

  1. Has anyone concerns about this solution? Still this feels like a workaround - is there really no other solution/method to manipulate the way how vaadin compares two objects?
  2. Still our question is open, how to access a specific virtuallist element. We didn’t find a method to ask for an element by providing an id.

Your workaround is the (best) solution.

I’m have the same problem. I’m using GridListDataView.
I solved it with override of equals and hashCode. That build hashcode based only on id and then compares it. I can now update it with refreshItem but still when i start .setFilter on my dataProvider the old object comes back. That’s what I still dont understand.
You can try this out:
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
RegisterTour tour = (RegisterTour) obj;
return Objects.equals(id, tour.id);

public int hashCode() {
    return Objects.hash(id);

@quirky-zebra @jocund-ferret
Thank you both for the responses!
The 2nd is useful, but we already use the .equals(…) for comparision over the whole objects’ attributes. We now need to think about whether to change that.

Best, Simon