View Full Version : Failing to complete RPC when using one parameter
I am having problems getting RPC to work when I pass one parameter. I tried to use String etc, but it still fails. It works if no parmeter is passed to the getCars method.
ExampleService
@RemoteServiceRelativePath("exampleService")
public interface ExampleService extends RemoteService {
List<Car> getCars(Car car);
}
// Car extends BaseModelData.
ExampleServiceAsync
public interface ExampleServiceAsync {
void getCars(Car car, AsyncCallback<List<Car>> cars);
}
And the code to the uses RPC
RpcProxy<Car, List<Car>> proxy = new RpcProxy<Car, List<Car>>() {
@Override
protected void load(Car car, AsyncCallback<List<Car>> cars) {
service.getCars(car, cars);
}
};
ListLoader loader = new BaseListLoader(proxy);
ListStore<Car> store = new ListStore<Car>(loader);
ComboBox<Car> combo = new ComboBox<Car>();
combo.setFieldLabel("Car");
combo.setDisplayField("name");
combo.setStore(store);
// example code
loader.load(new Car("test"));
The service implementation gill receive a Car object, but it fails to display any items in the combobox. It gives me a java.lang.ClassCastException. Seems like I am missing something here... :s
fother
9 Dec 2008, 10:53 AM
post the full stacktrace..
This is the stacktrace. As mentioned above, the code works fine without any parameter
ERROR] Uncaught exception escaped
java.lang.RuntimeException: java.lang.ClassCastException: com.example.test.client.model.Car
at com.extjs.gxt.ui.client.store.ListStore.onLoadException(ListStore.java:466)
at com.extjs.gxt.ui.client.store.ListStore$1.loaderLoadException(ListStore.java:135)
at com.extjs.gxt.ui.client.event.LoadListener.handleEvent(LoadListener.java:27)
at com.extjs.gxt.ui.client.event.LoadListener.handleEvent(LoadListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:74)
at com.extjs.gxt.ui.client.data.BaseLoader.onLoadFailure(BaseLoader.java:155)
at com.extjs.gxt.ui.client.data.BaseLoader$1.onFailure(BaseLoader.java:115)
at com.extjs.gxt.ui.client.data.RpcProxy$1.onSuccess(RpcProxy.java:35)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:254)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:226)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:217)
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:585)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.mac.MethodDispatch.invoke(MethodDispatch.java:71)
at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2909)
at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)
Caused by: java.lang.ClassCastException: com.example.test.client.model.Car
at com.extjs.gxt.ui.client.store.ListStore.onLoad(ListStore.java:428)
at com.extjs.gxt.ui.client.store.ListStore$1.loaderLoad(ListStore.java:131)
at com.extjs.gxt.ui.client.event.LoadListener.handleEvent(LoadListener.java:24)
at com.extjs.gxt.ui.client.event.LoadListener.handleEvent(LoadListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:74)
at com.extjs.gxt.ui.client.data.BaseLoader.onLoadSuccess(BaseLoader.java:166)
at com.extjs.gxt.ui.client.data.BaseLoader$1.onSuccess(BaseLoader.java:119)
at com.extjs.gxt.ui.client.data.RpcProxy$1.onSuccess(RpcProxy.java:33)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:254)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:226)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:217)
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:585)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.mac.MethodDispatch.invoke(MethodDispatch.java:71)
at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2909)
at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)
Car extends BaseModelData.
Eclipse gives me the following hint
"The method load(Object) belongs to the raw type Loader. References to a generic type Loader<C> should be parameterized"
So I changed this
ListLoader loader = new BaseListLoader(proxy);
to this
ListLoader<Car> loader = new BaseListLoader(proxy);
But this will fail, since ListLoader has the following defintion:
"ListLoader<C extends ListLoadConfig>"
I then changed Car to to extend BaseListLoadConfig and the compiler was happy. Though to be honest, I am not sure this is correct at all...
I am sure that most people already figured this out, any help is appreciated.
Thank you.
Problem is solved.
The solution was to let the Car extend BaseListLoadConfig instead.
The Cars would then be successfully loaded.
The next problem was that the ComboBox would re-fetch the Cars once clicked, and I assume that it then called Loader.load() without any argument causing a crash.
This is a subject for another thread though.
~o)
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.