PDA

View Full Version : RPC and deferred binding: doesn't load data



pbesi
16 Dec 2010, 6:44 AM
Hello. I'm trying to define deferred binding and GWT RPC.
I read about it at the URL http://www.sencha.com/blog/2008/07/14/preview-java-bean-support-with-ext-gwt/

More precisaly, I want to create a basic grid and load data from a javabean using GWT RPC.
After a debug, I can see the problem but I don't know how to solve it.
Follows my EntryPoint class:



public class RubricaTest implements EntryPoint {
......
private PersonaServiceAsync personaService;
private ListLoader<BeanModel> loader;
private ListStore<BeanModel> personaStore;
private ContentPanel gridPanel;
private Grid<BeanModel> grid;
......
personaService = (PersonaServiceAsync)GWT.create(PersonaService.class);
ServiceDefTarget endPoint = (ServiceDefTarget)personaService;
String moduleRelativeURL = GWT.getModuleBaseURL();
moduleRelativeURL += "getAllPersona";
endPoint.setServiceEntryPoint(moduleRelativeURL);
Registry.register(moduleRelativeURL, personaService);

RpcProxy<BeanModel> proxy = new RpcProxy<BeanModel>() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
personaService.getAllPersona(callback);
}
};

BeanModelReader reader = new BeanModelReader();
loader = new BaseListLoader(proxy,reader);

personaStore = new ListStore<BeanModel>(loader); <---- Here the problem!!!
.....



Debugging, I can see that personaStore object doesn't load the data coming from the service, but I don't know which is the reason.
I don't get any exception, I see the grid but without data.
Can anyone help me please?

Follows other code:
Here my service implementation PersonaServiceImpl.java:


public class PersonaServiceImpl extends RemoteServiceServlet implements PersonaService {

private static final long serialVersionUID = 7755502792126268297L;

@Override
public List<Persona> getAllPersona() {

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

Persona p1 = new Persona("Mario", "Rossi");
Persona p2 = new Persona("Gino", "Bianchi");

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

return persone;
}

}


It is also defined in my web.xml as follows:



<servlet>
<servlet-name>PersonaService</servlet-name>
<servlet-class>net.cooparcobaleno.server.PersonaServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PersonaService</servlet-name>
<url-pattern>/rubricatest/getAllPersona</url-pattern>
</servlet-mapping>


My async service interface is:


public interface PersonaServiceAsync {

public void getAllPersona(AsyncCallback<List<Persona>> callBack);

}

My service definition PersonaService.java is:



public interface PersonaService extends RemoteService {

public List<Persona> getAllPersona();

}

My gwt.xml file is:


<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='rubricatest'>

<source path='client'/>
<source path='shared'/>
<inherits name="com.extjs.gxt.ui.GXT"/>
<entry-point class="net.cooparcobaleno.client.RubricaTest"/>

</module>


Here my bean model object Persona.java:


public class Persona implements Serializable {

private static final long serialVersionUID = -2021563303213112570L;
private String nome;
private String cognome;

public Persona() {
}

public Persona(String nome, String cognome) {
this.nome = nome;
this.cognome = cognome;
}
....

follow set and get methods
.....


and finally, because of my deferrede binding, here my beanmodel interface:


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

}

sven
16 Dec 2010, 6:47 AM
I don't get any exception, I see the grid but without data.
Can anyone help me please?

Try to listen to the Loader.LoadException event on the loader. Maybe there is an exception.

pbesi
16 Dec 2010, 7:21 AM
Try to listen to the Loader.LoadException event on the loader. Maybe there is an exception.

Thank you sven, but I'm a newbie.
Could you please write how to make it? I think something like:



loader.addListener(Loader.LoadException, new Listener() {

@Override
public void handleEvent(BaseEvent be) {
????

}
});


Thank you
Pbesi

sven
16 Dec 2010, 7:24 AM
loader.addListener(Loader.LoadException, new Listener<LoadEvent>() {

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

}
});

pbesi
16 Dec 2010, 7:42 AM
Ok, done.
I didnt get any output on my console!!

Anyway, I can see that in the code above,


RpcProxy<BeanModel> proxy = new RpcProxy<BeanModel>() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
personaService.getAllPersona(callback);
}
};

the statement is yellow underlined. Eclipse suggests me that "AsyncCallback is a raw type. References to generic type AsyncCallback<T> should be parameterized". If I try to write "AsyncCallback<List<Persona>> callback" it tells me that RcpProxy must be overriden.... mmmhh I think there is some problem with the BeanModel object. Are you sure my code above is correct?
Arrrgg.. I'm getting crazy!

Thank you
Pbesi

sven
16 Dec 2010, 7:46 AM
Is the server code ever invoked? Have you tried to reproduce it in a small, standalone testcase implementing EntryPoint?

pbesi
16 Dec 2010, 8:00 AM
Yes, my PersonaServiceImpl is invoked, I just debugged it and I put a breakpoint inside. Anyway, mmmhh the sequence is:

1) personaStore = new ListStore<BeanModel>(loader);
2)grid = new Grid<BeanModel>(personaStore,cm);
3)PersonaServiceImpl call.

Perhaps before step 1 and 2, the service implementation should be called. Am I wrong?
Thank you

sven
16 Dec 2010, 8:01 AM
No should work also after. How does you columnmodel for your grid look like?

pbesi
16 Dec 2010, 11:49 PM
Here my code. It is called after store definition:



private void buildMainLayout(Viewport viewPort) {
LayoutContainer container = new LayoutContainer();
gridPanel = new ContentPanel();
gridPanel.setHeading("Elenco contatti");

BorderLayoutData center = new BorderLayoutData(LayoutRegion.CENTER,320);
center.setMargins(new Margins(5,0,0,0));

container.setLayout(new BorderLayout());
container.add(gridPanel,center);

BorderLayoutData containerCenter = new BorderLayoutData(LayoutRegion.CENTER,320);
viewPort.setLayout(new BorderLayout());
viewPort.add(container, containerCenter);

}

private void buildGridPanel() {

GridCellRenderer<BeanModel> personaNomeCell = new GridCellRenderer<BeanModel>() {

@Override
public Object render(BeanModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BeanModel> store, Grid<BeanModel> grid) {
return model.get(property);
}
};

GridCellRenderer<BeanModel> personaCognomeCell = new GridCellRenderer<BeanModel>() {

@Override
public Object render(BeanModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BeanModel> store, Grid<BeanModel> grid) {
return model.get(property);
}
};

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

ColumnConfig column = new ColumnConfig();
column.setId("nome");
column.setHeader("Nome");
column.setWidth(80);
column.setRenderer(personaNomeCell);
columns.add(column);

column = new ColumnConfig();
column.setId("cognome");
column.setHeader("Cognome");
column.setWidth(80);
column.setRenderer(personaCognomeCell);
columns.add(column);

final ColumnModel cm = new ColumnModel(columns);

grid = new Grid<BeanModel>(personaStore,cm);
grid.setColumnLines(true);
gridPanel.add(grid);

}

I attache also my onModuleLoad():



public void onModuleLoad() {
GXT.setDefaultTheme(Theme.BLUE, true);

defineService();
Viewport viewPort = new Viewport();
buildMainLayout(viewPort);
buildGridPanel();

RootPanel.get().add(viewPort);
loader.load();

}

Thank you
Pbesi

pbesi
20 Dec 2010, 1:03 AM
Hello, any other suggestion?
Is there an example somewhere?
Thank you
Pbesi