PDA

View Full Version : how to load XML based Grid using RpcProxy ?



gxtyas
27 Dec 2010, 2:24 PM
Sven,

I am trying to load xml based grid using RpcProxy but I am not sure how to return xml string .


here is the test code,here I see the grid with header but no data, why am i not seeing the xml data in the grid?



public class TestXmlGrid extends LayoutContainer{
/*
* Ext GWT 2.2.1 - Ext for GWT
* Copyright(c) 2007-2010, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FlowLayout(10));
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("author", "author", 100));
columns.add(new ColumnConfig("region", "region", 165));
columns.add(new ColumnConfig("title", "title", 100));
columns.add(new ColumnConfig("summary", "summary", 50));
columns.add(new ColumnConfig("url", "url", 50));
columns.add(new ColumnConfig("date", "date", 65));
// create the column model
ColumnModel cm = new ColumnModel(columns);
// defines the xml structure
ModelType type = new ModelType();
type.setRoot("menus");
type.setRecordName("menu");
type.addField("author");
type.addField("region");
type.addField("title");
type.addField("summary");
type.addField("url");
type.addField("date");
RpcProxy<PagingLoadResult<ModelData>> proxy = createRPCProxy();

XmlLoadResultReader<ListLoadResult<ModelData>> reader = new XmlLoadResultReader<ListLoadResult<ModelData>>(type);
final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy,
reader);
ListStore<ModelData> store = new ListStore<ModelData>(loader);
final Grid<ModelData> grid = new Grid<ModelData>(store, cm);
grid.setBorders(true);
grid.setLoadMask(true);
//grid.getView().setEmptyText("Please hit the load button.");
grid.setAutoExpandColumn("author");
ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
//panel.setIcon(Resources.ICONS.table());
panel.setHeading("XML Table Demo");
panel.setLayout(new FitLayout());
panel.add(grid);
panel.setSize(575, 350);
loader.load();
add(panel);
}
/**
* Create a GWT RPC proxy
* @return
*/
private final RpcProxy<PagingLoadResult<ModelData>> createRPCProxy() {
RpcProxy<PagingLoadResult<ModelData>> proxy = new RpcProxy<PagingLoadResult<ModelData>>() {
@Override
public void load(Object loadConfig, AsyncCallback<PagingLoadResult<ModelData>> callback) {
String asset ="";
String product ="";
TestAppRemoteService.App.getInstance().getTestXml(asset, product,(BaseListLoadConfig)loadConfig, callback);
}
};
return proxy;
}

}


Server side

public PagingLoadResult<ModelData> getTestXml(String asset, String product, BaseListLoadConfig pagingLoadConfig) {
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\"?>");
xml.append("<menus>");
xml.append("<menu>");
xml.append("<author>Bloodroot</author>");
xml.append("<region>Caltha palustris</region> ");
xml.append("<title>Mostly Shady</title> ");
xml.append("<summary>Summary Mostly Shady</summary> ");
xml.append("<url>www.sencha.com</url> ");
xml.append("<date>03/15/2006</date> ");
xml.append("</menu> ");
xml.append("</menus> ");

String xmlString =xml.toString();
List<String> list = new ArrayList<String>();
list.add(xmlString);
System.out.println("XML String == "+ xmlString);
return new BasePagingLoadResult(list, 0, 10);
}

sven
27 Dec 2010, 2:26 PM
Simple return it as string, not wrapped in a List.

gxtyas
27 Dec 2010, 5:38 PM
Simple return it as string, not wrapped in a List.

Thanks Sven, If I just return string then how will I pass the remote pagination attributes like offset, limit etc back to client ?

I would like to return the xml string along with pagination attributes, as I would like to bind the loader with the PagingToolBar, Please advice

sven
28 Dec 2010, 2:31 AM
The only thing you need to return is the totalcount. Simple add this to your xml and set it up in the ModelType