We are using a Tree component to display hierarchical information which is contained in a BeanItemContainer. In order to get a proper tree display we first add all of the BeanItems to the container and then invoke the setParent() method to establish the correct nesting of the items. This works fine for the initial tree but somehow breaks when we try to apply filtering to the container. At that point, any nesting disappears and all of the items in the tree become root level nodes (assuming they match the filter of course).
I’ve looked in the implementation of the filtering, but can’t discover exactly where this occurs and how to prevent it. Does Vaadin somehow empty the container and re-add all filter-matching items, thereby effectively deleting any parent relations I had set manually? If so, how can I prevent this from happening?
I have not looked in to this, but I’ll venture a guess anyway… Maybe your filter removes the parent items, leaving the items that pass the filter parent-less?
Yes, to me it seems this way. However we´re not using any specific filtering of our own, but simply provide a value to the com.vaadin.data.util.filter.SimpleStringFilter class. Still it´s odd to me this happens. We use an com.vaadin.data.util.filter.Or filter to perform the filtering.
I assume you are using BeanItemContainer with ContainerHierarchicalWrapper. As far as I can remember, unlike HierarchicalContainer, the wrapper class does not preserve parents of items that match a filter. While the documentation of Container.Filterable does state that what hierarchical container filtering means is container specific, it would be logical for these two standard container classes to behave the same way, or at least the behavior should be documented in them.