PDA

View Full Version : TreeStore is populating with data , but on UI its showing "null" in GXT 2.2.5



bhupesh117
23 Feb 2012, 9:51 AM
I am a newbie with GXT, I am trying to load my TreeGrid on UI by making a RpcProxy call to load data from back-end server. When I put breakpoints I saw that my TreeStore is getting populated correctly, and there isn't any other exception, but for some odd reason on UI in TreeGrid it shows "null" for both parent and child.

I am putting some code snippet here for your reference:





import java.util.Arrays;
import java.util.List;


import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.data.BaseTreeLoader;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelKeyProvider;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.data.TreeLoader;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.treegrid.TreeGrid;
import com.extjs.gxt.ui.client.widget.treegrid.TreeGridCellRenderer;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;




public class MyTreeGrid extends LayoutContainer {

public MyTreeGrid(){
setLayout(new FitLayout());
}


@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

final MyServiceAsync service = (MyServiceAsync)
Registry.get(TestAnalysisConstatns.MY_SERVICE);





RpcProxy<List<ModelData>> proxy = new RpcProxy<List<ModelData>>() {
@Override
protected void load(Object loadConfig,
AsyncCallback<List<ModelData>> callback) {
service.getResults("rc001",(FolderBean)loadConfig, callback);
}

};

TreeLoader<ModelData> loader = new BaseTreeLoader<ModelData>(proxy){
@Override
public boolean hasChildren(ModelData parent){

if (parent instanceof FolderBean){
System.out.println("Found parent = " + parent.getClass());
return true;
}else{
return false;
}
}

};


TreeStore<ModelData> store = new TreeStore<ModelData>(loader);

ColumnConfig title = new ColumnConfig("group", "", 200);
title.setRenderer(new TreeGridCellRenderer<ModelData>());


ColumnModel columnModel = new ColumnModel(Arrays.asList(title));
TreeGrid<ModelData> tree = new TreeGrid<ModelData>(store,columnModel);

tree.setAutoExpandColumn("group");
tree.expandAll();
tree.setBorders(true);
add(tree);
loader.load();
}
}




================

Beans used for the above application. FolderBean is the Parent Bean and NodeBean is the child bean.





import java.io.Serializable;
import java.util.List;


import com.extjs.gxt.ui.client.data.BaseTreeModel;


public class FolderBean extends BaseTreeModel implements Serializable {

String group;
String title;

public FolderBean(){
}
public FolderBean(String name) {
this.group = name;
}

public FolderBean(String group, List<NodeBean> children) {
this(group);
for ( BaseTreeModel model : children){
add(model);
}
}


public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}

}






import com.extjs.gxt.ui.client.data.BaseTreeModel;


public class NodeBean extends BaseTreeModel {

/**
*
*/
private static final long serialVersionUID = 1L;

String bestPracticeTitle;
String group;


public String getBestPracticeTitle() {
return bestPracticeTitle;
}
public void setBestPracticeTitle(String bestPracticeTitle) {
this.bestPracticeTitle = bestPracticeTitle;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}


}

Am I missing anything here?? I am really stuck with this and have already gone through all possible posts on internet. I would really appreciate help with this!!