PDA

View Full Version : TreeStore and JSON



OBELIX
7 Jun 2010, 12:21 PM
Hi,

I have a "java.lang.ClassCastException" when i want to put JSON data in a Tree.

I think my JSON representation is wrong and/or my ModelType is wrong.

An idea ?

Tks,

Obelix.


Here is my JSON string :
{"items":[{"id":1,"name":"AleafNode","leaf":false,"children":[{"id":2,"name":"AleafNode","leaf":true},{"id":2,"name":"AnotherleafNode","leaf":true}]},{"id":2,"name":"BleafNode","leaf":true}]}
Here is my Code :

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, theDocsUrl);
HttpProxy<ListLoadResult<ModelData>> proxy = new HttpProxy<ListLoadResult<ModelData>>(builder);

ModelType type = new ModelType();
type.setRoot("items");
//type.setRecordName("id");
type.addField("id", "id");
type.addField("name", "name");
type.addField("children", "children");

JsonLoadResultReader<List<ModelData>> reader = new JsonLoadResultReader<List<ModelData>>(type);


TreeLoader<ModelData> loader = new BaseTreeLoader<ModelData>(proxy, reader);

loader.addLoadListener(new LoadListener() {
@Override
public void loaderLoadException(LoadEvent le) {
MessageBox.alert("Info",le.exception.toString() ,null);
}
public void loaderLoad(LoadEvent le) {

}
});

sven
7 Jun 2010, 12:26 PM
JsonLoadResultReader returns a ListLoadResult while it has to return a list

OBELIX
7 Jun 2010, 1:05 PM
I don't understand...
Do you have a piece of code ?
Thks,
Obelix

sven
7 Jun 2010, 1:11 PM
http://www.extjs.com/examples-dev/explorer.html#asyncxmltree

Take a look at his and simple change it from xml to json.

OBELIX
7 Jun 2010, 11:01 PM
Thanks a lot : I have no "java.lang.ClassCastException"but could you confim my JSON Representation with my ModelType below ?

Thks.

Obelix

{"items":[{"id":1,"name":"AleafNode","leaf":false,"children":[{"id":2,"name":"AleafNode","leaf":true},{"id":2,"name":"AnotherleafNode","leaf":true}]},{"id":2,"name":"BleafNode","leaf":true}]}


ModelType type = new ModelType();
type.setRoot("items");
//type.setRecordName("id");
type.addField("id", "id");
type.addField("name", "name");
type.addField("children", "children");