Refresh problems with a lazy loading tree

Hi,

I’m facing a little refresh problem while trying to implement a lazy loading tree with Vaadin (6.2.6) : I’ve added an expand listener to the tree that checks if the expanded item was already loaded, and if not, asynchronously retrieves it’s children (as a http get request to a REST service that produces JSON, but that’s beside the point).

Here is basically what my code looks like :


@Override
public void nodeExpand(final ExpandEvent event) {
	ContentReponse content = ... //parsed from the json response
	//iterate over the response entries
	for (RepositoryEntry entry : content.content) {
		Item item = tree.addItem(entry.name); //create a new item in the tree
		tree.setParent(entry.name, event.getItemId()); //sets the new item's parent
	}
	:
	: // <-- here
}

This sort of works : when I expand a node “N” in the tree, the listener is fired and the data is retrieved, but the newely retrieved node children are not shown, which is to be expected, since their retrieval doesn’t block Vaadin from returning the reply.

But then, any following expand/collapse I perform on any other node in the tree expands the node “N” and shows it’s children.

Is there a way to force the tree, or even better : a node, to update itself ? I’m guessing it should go where I placed the “// ← here” in my code snippet.

I tried tree.requestRepaint but to no avail.

Thanks !


Edit:

Just saw this thread : http://vaadin.com/forum/-/message_boards/message/131802#_19_message_131949 (which wasn’t yielded by any of the searches I made before posting this message ?). I’m doing basically the same thing Marko Grönroos did in his code example and yet I’m experiencing the weird behaviour described above.

If this helps, the tree update is performed by a different thread than the request’s thread. I took care to enclose my code in a synchronisation block on Vaadin’s Application instance :

synchronized(tree.getApplication()){
:
:
}

Hi again,

After a good night’s sleep and broadening the scope of my search to use keywords like “thread” and “push”, I think I now understand why my code isn’t working as I expected :

My tree state is changed in the server by a background thread. The modifications are stored in the session but not sent to the client (Vaadin doesn’t support pushing modifications from the server to the client).

The next time the client interacts with the server, the queued modifications stored in the latter are sent to the former.

Using a (hidden) progressbar that continually polls the server is a possible solution, but in my case, I’m not very fond of this method, unless I use a very short poll period.

I’ll just rewrite my app to use synchronous tree updating.

Cheers.