PDA

View Full Version : RPC and ClassCastException



pbesi
4 Jan 2011, 7:36 AM
Hello.
I'm getting the following exception:



java.lang.ClassCastException: net.cooparcobaleno.shared.model.Persona cannot be cast to com.extjs.gxt.ui.client.data.ModelData
at com.extjs.gxt.ui.client.store.ListStore.onLoad(ListStore.java:566)
at com.extjs.gxt.ui.client.store.ListStore$1.loaderLoad(ListStore.java:173)
at com.extjs.gxt.ui.client.event.LoadListener.handleEvent(LoadListener.java:23)
at com.extjs.gxt.ui.client.event.LoadListener.handleEvent(LoadListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:178)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:86)
at com.extjs.gxt.ui.client.data.BaseLoader.onLoadSuccess(BaseLoader.java:174)
at com.extjs.gxt.ui.client.data.BaseLoader$1.onSuccess(BaseLoader.java:127)
at com.extjs.gxt.ui.client.data.RpcProxy$1.onSuccess(RpcProxy.java:36)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:215)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
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)
...............


Reading some other threads it seems my code is ok. I cannot find any problem.

Here my domain object:



public class Persona implements Serializable {

private static final long serialVersionUID = 6302137404622656800L;

private Integer id;
private String nomNome;
private String nomCognome;

public Persona() {}

public Persona(Integer id, String nome, String cognome) {
super();
this.id = id;
this.nomNome = nome;
this.nomCognome = cognome;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getNomNome() {
return nomNome;
}

public void setNomNome(String nomNome) {
this.nomNome = nomNome;
}

public String getNomCognome() {
return nomCognome;
}

public void setNomCognome(String nomCognome) {
this.nomCognome = nomCognome;
}

}


My PersonaBeanModel interface:


@BEAN(net.cooparcobaleno.shared.model.Persona.class)
public interface PersonaBeanModel extends BeanModelMarker {
}

and my entrypoint:


.......
final PersonaServiceAsync personaService = (PersonaServiceAsync)Registry.get(RubricaLabConstants.PERSONA_SERVICE);
RpcProxy<List<Persona>> rpcProxy = new RpcProxy<List<Persona>>() {

@Override
protected void load(Object loadConfig, AsyncCallback<List<Persona>> callback) {
personaService.loadPersona(callback);

}
};

ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(rpcProxy);
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
loader.load();

loader.addListener(Loader.LoadException, new Listener<LoadEvent>() {

public void handleEvent(LoadEvent le) {
le.exception.printStackTrace();

}
});

Grid<BeanModel> gridPersona = new Grid<BeanModel>(store,columnModel);
......................


Please, any suggestion?
Thank you
Pbesi

sven
4 Jan 2011, 11:29 AM
Your loader needs to use a BeanModelReader

pbesi
5 Jan 2011, 12:23 AM
Ok, I don't get the classexception but it doens't load the data. Anyway debugging my ServiceImpl class, it is executed and it returs a list of objects. I send you my service code:

Here my serviceImpl that return a list of objects:


public class PersonaServiceImpl extends RemoteServiceServlet implements PersonaService {

private static final long serialVersionUID = -4948994322183792569L;

public List<Persona> loadPersona() {

List<Persona> persone = new ArrayList<Persona>();

Persona p1 = new Persona();
p1.setId(new Integer(1));
p1.setNomNome("Mario");
p1.setNomCognome("Rossi");

Persona p2 = new Persona();
p1.setId(new Integer(2));
p2.setNomNome("Gino");
p2.setNomCognome("Bianchi");

persone.add(p1);
persone.add(p2);

return persone;
}

}


My serviceasync


public interface PersonaServiceAsync {

public void loadPersona(AsyncCallback<List<Persona>> callback);

}


and my service:


@RemoteServiceRelativePath("persona-service")
public interface PersonaService extends RemoteService {
List<Persona> loadPersona();



The whole code is working using MVC pattern, I mean dispatcher, view and controller objects.
Is it possible this is the problem?
Thank you
Pbesi