Search code examples
vaadintreegrid

Vaadin 14 TreeGrid - Cannot add the same item multiple times


Working on a project that will display hierarchies of "tasks". I'm running into a problem where it will not allow for multiple entries of the same object. From what I can tell, the "duplicate" item is under a different parent.

The domain data allows for this - a given task may appear in lots of places.

It would seem that this is intentional (maybe), but is there a way around this?


Solution

  • It's intentional to a degree; each Grid and TreeGrid data item is expected to be unique. You could work around this by creating your own implementation of the hierarchical DataProvider class (for example extend AbstractHierarchicalDataProvider) which overrides the getId method along with the other required methods. The return value of this method needs to be unique per item, as it's used as a hash key.