How to populate a CellTree with data from the back end
The CellTree has a constructor that takes a TreeModel. I can't set the tree model via a setter.
I fetch the data for the tree via an asynchronous rpc call, this call is triggered on creation of the presenter corresponding to the view that holds the tree, but that means the view is also created, without the tree model populated with the necessary data.
When the data does return I set the root node on the model, but the model is already created without a root so it doesn't get the update...
I've gone this route because I want to have better control over the rendering of the tree nodes.
Two possible solutions...
Hold the render of the view until the fetch has come back so that when the tree is created the model has all the information - How do I do this?
Once the data comes back, and is set on the model, tell the tree to up开发者_JAVA百科date... How do I do this?
- When you build a view you must setup your CellTree over ListDataProvider.
- When you get your data throw RPC call you only update ListDataProvider, your CellTree will be updated and re rendered automatically.
Please read Providing Dynamic Data of Developer's Guide - Cell Widgets. Heres quick quote:
ListDataProvider binds your cell widget to a java.util.List. Any changes to the internal list, which can be accessed via getList(), will be reflected in the views. The views are updated at the end of the current event block, so you can make multiple synchronous changes without causing multiple refreshes of the views.
Using ListDataProvider or AsyncDataProvider (If you want to dynamically update the table with data instead of loading everything at once) will perfectly work for you.
精彩评论