TreeViewModel and AsyncDataProvider

Skip to first unread message


Dec 26, 2010, 12:27:01 AM12/26/10
I have a 3 level CellBrowser. Everything is working fine using a ListDataProvider except that it's too long to grab the data from the server. So I want to use the AsyncDataProvider to fetch only the data that the user actually needs. Basically what I want to do is when the user selects the level1 value, the level2 provider executes a RPC call to get the level2 data based on the selected level1 parent. The problem is that the onRangeChanged method is called before the onSelectionChange, so when the RPC call is done the level1 value is still null. What is the proper way to use AsyncDataProvider to grab the level2 data depending on the level1 selected value?

public class SportTreeModel implements TreeViewModel, Handler {
  private AsyncDataProvider<Level1Node> level1Provider;
  private AsyncDataProvider<Level2Node> level2Provider;
  private final SingleSelectionModel<Level1Node> level1SelectionModel;
  // In the construtor I create these objets
  // In getNodeInfo I link a cell with the data provider and the selection model
    public void onSelectionChange(SelectionChangeEvent event) {
        Object src = event.getSource();
        if (src == level1SelectionModel) {
            Level1Node level1 = level1SelectionModel.getSelectedObject();
            ((MyAsyncLevel2Provider) level2Provider).setLevel1(level1.getValue());


Dec 26, 2010, 3:36:29 AM12/26/10
to Google Web Toolkit
I use a custom TreeViewModel instead of handling selection events.

When a user clicks on a level 1 node, TreeViewModel.getNodeInfo(...)
method is called

The method creates a data provider that corresponds to the type of
value parameter.

The data provider initiates an RPC call in its constructor.

When the data provider receives results back from the server it
populates itself with the data received by calling updateRowCount()
and updateRowData()

This works well when the number of children under parent node is
small. If it is large AbstractDataProvider<T>.onRangeChanged() can be
used to query only currently visible children.

Is this something you are looking for?


Dec 26, 2010, 4:41:25 PM12/26/10
Perfect I overlooked the fact that when the level1 node is selected, the call to getNodeInfo provides the current seleced level1 node.
Thanks for the help
Reply all
Reply to author
0 new messages