garyiskidding
24 Jul 2009, 4:01 AM
I am trying to fetch json as string from my server and then use it to populate a grid.
The panels etc all render but the grid is not populated and i get this error:
load exception = com.google.gwt.json.client.JSONArray cannot be cast to com.google.gwt.json.client.JSONObject
java.lang.ClassCastException: com.google.gwt.json.client.JSONArray cannot be cast to com.google.gwt.json.client.JSONObject
at com.extjs.gxt.ui.client.data.JsonReader.read(JsonReader.java:52)
at com.extjs.gxt.ui.client.data.RpcProxy$1.onSuccess(RpcProxy.java:32)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
My code looks like this:
//proxy
RpcProxy<String> proxy = new RpcProxy<String>() {
@Override
public void load(Object loadConfig, AsyncCallback<String> callback) {
Map requestData = new HashMap();
requestData.put("action", "testMe");
service.doService(requestData, callback);
}
};
//reader
JsonReader<ListLoadConfig> jsonReader = new JsonReader<ListLoadConfig>(AssociateModel.getModelType());
BaseListLoader loader = new BaseListLoader(proxy, jsonReader);
loader.addLoadListener(new LoadListener() {
public void loaderBeforeLoad(LoadEvent le) {
System.out.println("before load");
}
public void loaderLoad(LoadEvent le) {
System.out.println("load succeeded");
}
public void loaderLoadException(LoadEvent le) {
System.out.println("load exception = " + le.exception.getLocalizedMessage());
le.exception.printStackTrace();
}
});
//store1
final ListStore store1 = new ListStore<ModelData>(loader);
store1.addStoreListener(new StoreListener<BaseModel>() {
public void storeUpdate(StoreEvent<BaseModel> se) {
List<Record> modefied = store1.getModifiedRecords();
if (null != modefied) {
for (Record record : modefied) {
Collection propertyNames = record.getPropertyNames();
for (Iterator iterator = propertyNames.iterator(); iterator.hasNext();) {
String property= (String) iterator.next();
System.out.println("property:" + property + ",value:" + record.get(property));
}
}
}
}
});
loader.load();
and the model type is being created as:
public static ModelType getModelType(){
ModelType type = new ModelType();
type.setTotalName("totalCount");
type.setRecordName("id");
type.addField("id");
type.addField("firstName");
type.addField("lastName");
type.addField("location");
return type;
}
The json returned from the server is :
[{
"totalCount":2
},
{
"data":[{
"lastName":"lastName","location":"location","id":"id","firstName":"firstName"
},{
"lastName":"lastName2","location":"location2","id":"id2","firstName":"firstName2"
}]
}]
I get this error while loading the loader. Please suggest what could be going wrong.
The panels etc all render but the grid is not populated and i get this error:
load exception = com.google.gwt.json.client.JSONArray cannot be cast to com.google.gwt.json.client.JSONObject
java.lang.ClassCastException: com.google.gwt.json.client.JSONArray cannot be cast to com.google.gwt.json.client.JSONObject
at com.extjs.gxt.ui.client.data.JsonReader.read(JsonReader.java:52)
at com.extjs.gxt.ui.client.data.RpcProxy$1.onSuccess(RpcProxy.java:32)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
My code looks like this:
//proxy
RpcProxy<String> proxy = new RpcProxy<String>() {
@Override
public void load(Object loadConfig, AsyncCallback<String> callback) {
Map requestData = new HashMap();
requestData.put("action", "testMe");
service.doService(requestData, callback);
}
};
//reader
JsonReader<ListLoadConfig> jsonReader = new JsonReader<ListLoadConfig>(AssociateModel.getModelType());
BaseListLoader loader = new BaseListLoader(proxy, jsonReader);
loader.addLoadListener(new LoadListener() {
public void loaderBeforeLoad(LoadEvent le) {
System.out.println("before load");
}
public void loaderLoad(LoadEvent le) {
System.out.println("load succeeded");
}
public void loaderLoadException(LoadEvent le) {
System.out.println("load exception = " + le.exception.getLocalizedMessage());
le.exception.printStackTrace();
}
});
//store1
final ListStore store1 = new ListStore<ModelData>(loader);
store1.addStoreListener(new StoreListener<BaseModel>() {
public void storeUpdate(StoreEvent<BaseModel> se) {
List<Record> modefied = store1.getModifiedRecords();
if (null != modefied) {
for (Record record : modefied) {
Collection propertyNames = record.getPropertyNames();
for (Iterator iterator = propertyNames.iterator(); iterator.hasNext();) {
String property= (String) iterator.next();
System.out.println("property:" + property + ",value:" + record.get(property));
}
}
}
}
});
loader.load();
and the model type is being created as:
public static ModelType getModelType(){
ModelType type = new ModelType();
type.setTotalName("totalCount");
type.setRecordName("id");
type.addField("id");
type.addField("firstName");
type.addField("lastName");
type.addField("location");
return type;
}
The json returned from the server is :
[{
"totalCount":2
},
{
"data":[{
"lastName":"lastName","location":"location","id":"id","firstName":"firstName"
},{
"lastName":"lastName2","location":"location2","id":"id2","firstName":"firstName2"
}]
}]
I get this error while loading the loader. Please suggest what could be going wrong.