I have a big Problem with my grid selection (by click, not programmatically).
When i select an item in my grid, totally normal, an then click a button that changes two of many values in the object, a refreshAll will be triggert. But now I can’t selct the item by click.
I go deep into and find out that in the map of items, where vaadin want to select it with the “event.detail.itemKey” = “50”, the map returns null. So when I catch the click event in my itemClickListener the value of the event is null. In the Map are keys from 1 to 51 but 50 is missing and the item I changed is twice inside the map. On the correct position (3) and 51.
I fixed the problem at the first place but with a really ugly and not a long term solution. I removed these two values from my equals and hash code fuctions. It looks like that vaadin then recognized these two objects are the same an make a correct replace. But its not possible to remove all values that could be changed in an object from there equals and hash code but they are not the same.
Sounds like a Bug for me. When not I really need a better solution then my actual! I don’t want to have a vaadin equals method and a second one the recognize that they are really the same.
One thing to look out for is the equals and hashCode implementations of the item class. If either of those are implemented in a way that changes when edits are made, then that will probably lead to weird issues like what you’re describing.
I use lombok to generate equals and hashCode implementation. But I’m confused why this method will be used? When I change an item in my list and refresh the grid, the items are never be the same, that’s why I refresh the grid. So why use equals and hashCode to find the one to replace with ne same (changed) item?
@EqualsAndHashCode from Lombok does by default produce implementations that cause problems with when objects stored in various collections are modified. You can verify this by adding an instance to a HashSet, then changing the value of some property in the instance and then set.contains(instance) will in most cases return false even though the instance is still present according to the set’s iterator.
The mechanisms inside Grid are sensitive to similar effects. I have seen so many similar cases that I’ve learned to always start by checking equals and hashCode before even considering other options. In this case, it’s probably related to the fact that resetAll() doesn’t reset the selection.