PDA

View Full Version : XML Tree loading



stormblow
4 Feb 2010, 1:45 PM
Hi,

I'm trying to create a tree which loads its children on demand using a remote service which returns xml ( http://www.extjs.com/examples-dev/explorer.html#asyncxmltree (http://www.extjs.com/forum/../examples-dev/explorer.html#asyncxmltree))

My XML file is the following :


<items>
<item id="1" name="root" folder="true">
<item id="2" name="gestion objets" folder="false">gestion objets</item>
</item>
</items>
And the code is the following :


public void onModuleLoad() {
Log.setCurrentLogLevel(Log.getLowestLogLevel());
Log.setUncaughtExceptionHandler();

ContentPanel west = new ContentPanel();
west.setBodyBorder(false);
west.setLayout(new AccordionLayout());
west.setLayoutOnChange(true);
west.setHeading("Admin navigation");
west.setWidth(200);

ContentPanel navigation = new ContentPanel();
navigation.setHeading("Navigation");
navigation.setAnimCollapse(false);
navigation.setHeight(600);

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/resources/xml/xmltreeloader.xml");
HttpProxy<ListLoadResult<ModelData>> proxy = new HttpProxy<ListLoadResult<ModelData>>(builder);

ModelType type = new ModelType();
type.setRecordName("item");
type.setRoot("items");
type.addField("id", "@id");
type.addField("name", "@name");
type.addField("folder", "@folder");

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

TreeLoader<ModelData> loader = new BaseTreeLoader<ModelData>(proxy,reader) {
@Override
public boolean hasChildren(ModelData parent) {
return "true".equals(parent.get("folder"));
}

@Override
protected Object prepareLoadConfig(Object config) {
return super.prepareLoadConfig(config);
}
};
TreeStore<ModelData> store = new TreeStore<ModelData>(loader);
Log.info(" "+store.getAllItems().isEmpty());

final TreePanel<ModelData> tree = new TreePanel<ModelData>(store);
tree.setDisplayProperty("name");
tree.setWidth(315);

loader.load();

navigation.add(tree);
west.add(navigation);
RootPanel.get().add(west);
}
This code returns no errors. Unfortunately the tree isn't loaded and


Log.info(" "+store.getAllItems().isEmpty());
returns true...

Does anyone have any idea?

Thank you very much.

stormblow
5 Feb 2010, 11:47 AM
I still haven't find the error... Please help me :((
Thanks

dtandrea
25 Feb 2010, 4:18 AM
I have the same problem, please help!

szaboaz
7 Mar 2010, 4:45 AM
Hi,

if you take a good look at XmlReader's source code, you'll realize, that it handles only one "level" of xml, no children, no parents. In the AsyncXmlTree example at http://www.extjs.com/examples-dev/explorer.html#asyncxmltree (http://www.extjs.com/forum/../examples-dev/explorer.html#asyncxmltree) the hierarchy is provided by server-side logic (the servlet gets an id of a parent, and returns the children).

If you're looking for a way to fill a TreePanel with the contents of an xml file (which is specially created for this purpose), look at this thread:

http://www.extjs.com/forum/showthread.php?t=56413

Best,
Arpad