TreeTable bound to a dynamically loading container

Hi everybody. I am currently evaluation Vaadin but have encountered some problems with the TreeTable component. I have bound my TreeTable to a custom BeanContainer which also implements Container.Hierarchical. I want the container to fetch child nodes dynamically with every expanded node but I cannot get this to play with the TreeTable.

I guess I have come across a few bugs, but feedback is much appreciated since I may have misunderstood all of this. I use Vaadin 7.1.7 and have mainly tested this in Chrome 30 for Windows.

Approach 1: In my implementation of getChildren I do the call fetching child nodes, add these to the container and return the ids. Something like:

@Override
public Collection<?> getChildren(Object itemId) {
        
     Collection<Node> nodes = retrieveChildren(itemId); 
     addAll(nodes); 
        
        return FluentIterable.from(nodes).transform(new Function<Node, Long>() {
            @Override
            public Long apply(Node node) {
                return node.getId();
            }
        }).toImmutableList();
  }

This, however, leads to unexpected results. The retrieved child nodes seem to be duplicated in the tree view. They do appear as child nodes where they should be, but are also added at some other place in the tree view. I also noticed that when binding my container to a Tree instead, it causes an Exception:

java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written.

Are you not allowed to add items in getChildren() ?

Approach 2: (inspired by some answers on this forum) Add an expand listener to the tree table and retrieve and add child nodes on nodeExpand. Something like:

     treeTable.addExpandListener(new Tree.ExpandListener() {

            @Override
            public void nodeExpand(Tree.ExpandEvent event) {
            Collection<Node> nodes = container.retrieveChildren(itemId); 
            container.addAll(nodes); 
            }
        });

The problem here is that the child nodes do not show when the parent item is expanded. It seems there is a first call to getChildren coming from Table.setCurrentPageFirstItemIndex:1463. The expandEvent is fired after this (TreeTable.toggleChildVisibility:558) and for some reason the TreeTable does not manage to refresh after the retrieved children are added. If the node is collapsed and then expanded again, the child nodes are there. Calls to refreshRowCache() and markAsDirty() do not seem to make any difference.

Any ideas how to go forward from here to make the TreeTable work? Should I report these problems as bugs?