BKl
BKl

Reputation: 415

Smartgwt: refreshing data on the tree component

I'm using smartgwt tree component. I've tried to extend it to usertree like at class below:

public UserTree() { 

    final List<NewNode> lista = new ArrayList<NewNode>();
    lista.add(new NewNode(4,"333"));
    setModelType(TreeModelType.PARENT);  
    setIdField("UserViewId");  
    setParentIdField("ReportsTo");  
    setNameProperty("Uzytkownicy");
    zapelnijListeUzytkownikow(lista);
    setRootValue(1);
    setData(userViewData);

    administrationService.zapelnijListeWezlow(token, new AsyncCallback<List<NewNode>>() {
        @Override
        public void onSuccess(List<NewNode> result) {

            zapelnijListeUzytkownikow(result);  
            setData(userViewData);
        }

        @Override
        public void onFailure(Throwable caught) {
            Window.alert("fail");
        }
    };  
}

protected TreeNode[] zapelnijListeUzytkownikow(List<NewNode> result) {

    userViewData = new TreeNode[12];
    /*  userViewData = new TreeNode[result.size() + 4];

    userViewData[0] = new UserViewTreeNode("2", "1", "Administratorzy");
    userViewData[1] = new UserViewTreeNode("3", "1", "Uprzywilejowani");
    userViewData[2] = new UserViewTreeNode("4", "1", "Uzytkownicy");
    userViewData[3] = new UserViewTreeNode("5", "1", "Pozostali");
    int i = 4;
    for(NewNode nn : result) {
       userViewData[i] = new UserViewTreeNode(String.valueOf(nn.getId()), "2", nn.getName());
       i++;
    }*/
    userViewData[0] = new UserViewTreeNode("2", "1", "Administratorzy");
    userViewData[1] = new UserViewTreeNode("3", "1", "Uprzywilejowani");  
    userViewData[2] =new UserViewTreeNode("4", "1", "Uzytkownicy");
    userViewData[3] =new UserViewTreeNode("5", "1", "Pozostali");  
    userViewData[4] = new UserViewTreeNode("18", "2", "Fasola Jan");
    userViewData[5] =new UserViewTreeNode("19", "2", "Puchatek Jakub");
    userViewData[6] =new UserViewTreeNode("20", "3", "Klapouchy");
    userViewData[7] =new UserViewTreeNode("21", "3", "Król Lew");
    userViewData[8] =new UserViewTreeNode("22", "4", "Bolek");
    userViewData[9] =new UserViewTreeNode("23", "4", "Lolek");
    userViewData[10] =new UserViewTreeNode("24", "5", "Gargamel");
    userViewData[11] =new UserViewTreeNode("25", "5", "Ciamajda");

    return userViewData;
}

I wanna use asyncallback to put data from database to this tree. It is working well, but if I wanna use setData method in onSuccess method I got an error:

"Cannot change configuration property 'data' to [Lcom.smartgwt.client.widgets.tree.TreeNode;@3c01807 after the component has been created."

How could I refresh the data on the tree after it created? I wanna clean all the values on the tree and put values generated by ZapelnijListeWezlow method Thanks for any help!

Upvotes: 1

Views: 2354

Answers (2)

gpapaz
gpapaz

Reputation: 909

The databounded elements (e.g. TreeGrid and ListGrid) created without a "proper" Datasource (i.e. client side one) can only be loaded with data upon creation, as I am sure you already know. The message you get states that exactly. Another solution, and the proper one IMO, although more complex, is to create a Datasource which is not depending on the SC server, thus working with LGPL version of the smartgwt library, but utilizes the transport methods of the GWT (i.e. GWT-RPC or the RequestBuilder. This will allow you to reload the tree through a simple fetch(). You can find details of such an approach in the following forums thread. It discusses the GWT-RPC approach, but you can extrapolate it to create the RequestBuilder one.

Upvotes: 0

BKl
BKl

Reputation: 415

I think I found an answer. The tree component is read only. but treegrid not. so I decided to extend TreeGrid to UserTreeGrid, and always when I want refresh the tree I just do something like that:

UserTreeView ust = new UserTreeView(); ... ... ... ust.setData(tree) <-- I cannot put new values to the tree, so I create new tree with new data and put it here instead the old tree.

Upvotes: 1

Related Questions