PDA

View Full Version : JSON Tree generation using Servlet



muthu_912
2 Mar 2010, 4:30 AM
I am trying to to use EXTJs JSON tree in my web application.
Servlet is used as dataUrl for Json creation. But this servlet is not called. So i don't get the tree view. Please help me with this.
This is my Java script:
Ext.onReady(function(){
var tree = new Ext.tree.TreePanel({
renderTo:'tree-div',
//id:'tree-div',
title: 'My Task List',
height: 300,
width: 400,
useArrows:true,
autoScroll:true,
animate:true,
enableDD:true,
containerScroll: true,
rootVisible: true,
frame: true,
root: {
text: 'Auto',
draggable:false,
id:'source'
}
// auto create TreeLoader
dataUrl: "/SampleTree/SampleServlet.do" // this is the servlet for JSON creation.
});

tree.render();
tree.getRootNode().expand(true);
});

and the servlet code is
ArrayList jsonObjectResponse = new ArrayList();
java.io.Writer out = response.getWriter();
SampleValueObject vo = new SampleValueObject();
vo.setId(1);
vo.setText("Absolute");
vo.setCls("folder");
vo.setLeaf(true);
jsonObjectResponse.add(vo);
String str = new flexjson.JSONSerializer().serialize( jsonObjectResponse);
System.out.println("Hi am here " +str);
out.write(str);
the SampleValueObject is a class having setters and getters of id,cls,text and leaf.

cnestor
2 Mar 2010, 4:21 PM
You might want to check your web.xml and make sure your servlet mappping is valid for your call '/SampleTree/SampleServlet.do' (using Struts framework I believe).

Cyril