PDA

View Full Version : Populating a grid store with RPC calls with an object that implements the BaseModel



azizbodal
2 Jan 2011, 10:15 AM
I want to know if it possible to implement a grid that is populated via RPC using an object that extends the BaseModel or do I have to use the BeanModel?

If so are there any good examples that use the BaseModel and implement RPC? I have looked at the example explorer but have not seen any that do. They all seem to be getting data that is client side.

I am not clear on the pros and cons of using the BaseModel vs the BeanModel. If anyone can direct me to a good article or example, I'd appreciate it.

Thanks.

sven
2 Jan 2011, 10:17 AM
I am not clear on the pros and cons of using the BaseModel vs the BeanModel. If anyone can direct me to a good article or example, I'd appreciate it.
BeanModel is a BaseModel. Its just easier to use if you already have defined your objects. If you want to have everything GXT based you can also use BaseModel directly. This more depends on your needs.


I want to know if it possible to implement a grid that is populated via RPC using an object that extends the BaseModel or do I have to use the BeanModel?
Simple return them same as you would return BeanModel instances. In your loader, just dont use any reader.

azizbodal
2 Jan 2011, 10:59 AM
Thank you for the clarification.

I tried to implement a grid using the BaseModel but I get my Server side code throwing an exception (NoClassDefFoundError) on the Customer2 class that I created. Is there any other class I need to implement?

My implementation is as follows:

Server side impl code snippet:


public List<Customer2> getCustomers2() {
// TODO Auto-generated method stub
Customer2 md = new Customer2("test customer", "test@gmail.com", 30);
ArrayList<Customer2> c = new ArrayList<Customer2>();
c.add(md);
return c;
}


Customer2 that extends the BaseModel:


package com.extjs.gxt.samples.resources.client.model;

import com.extjs.gxt.ui.client.data.BaseModel;

public class Customer2 extends BaseModel {
public Customer2(String Name, String Email, double Age) {
set("Name", Name);
set("Email", Email);
set("Age", Age);
}
public String getName(){
return (String) get("Name");
}

public String getEmail(){
return (String) get("Email");
}

public int getAge(){
Integer i = (Integer) get("Age");
return i.intValue();
}
}


Client side code to populate grid:


RpcProxy<List<Customer2>> proxy2 = new RpcProxy<List<Customer2>>() {

@Override
protected void load(Object loadConfig,
AsyncCallback<List<Customer2>> callback) {
service.getCustomers2(callback);
}
};
final BaseListLoader<ListLoadResult<Customer2>> loader2 = new BaseListLoader<ListLoadResult<Customer2>>(proxy2);
ListStore<Customer2> store2 = new ListStore<Customer2>(loader2);
loader2.load();
final Grid<Customer2> grid2 = new Grid<Customer2>(store2, cm);

ContentPanel panel2 = new ContentPanel();
panel2.setHeading("Grid Example");
panel2.setSize(400, 200);
panel2.setIcon(Resources.ICONS.table());
panel2.setLayout(new FitLayout());
panel2.add(grid2);


What am I missing?

sven
2 Jan 2011, 11:15 AM
I tried to implement a grid using the BaseModel but I get my Server side code throwing an exception (NoClassDefFoundError) on the Customer2 class that I created

Is the gxt.jar on your server classpath?

azizbodal
2 Jan 2011, 11:27 AM
gxt.jar is in my Java Build Path of my gwt project. Do I need to additionally specify GXT.jar in my server path somewhere? My BeanModel server side procedure seems to work fine:



@Override
public List<Customer> getCustomers() {
// TODO Auto-generated method stub
List<Customer> lstCustomers = new ArrayList<Customer>();
Customer c = new Customer("Aziz", "azizbodal@gmail.com", 30) ;
lstCustomers.add(c);
return lstCustomers;
}


The Customer2 class I created is in my com.extjs.gxt.samples.resources.client.model path, the same location as the BeanModel implementation of Customer if that helps.

sven
2 Jan 2011, 11:29 AM
Customer has no depency to GXT than. If you use BaseModel you have a depency to the gxt.jar and you need to make sure your server has access to it in its classpath.

azizbodal
2 Jan 2011, 11:38 AM
If you use BaseModel you have a depency to the gxt.jar and you need to make sure your server has access to it in its classpath.

How do I verify that the server has access to it in Eclipse?

The error I am getting is:

[ERROR] javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.util.List gwt.datgrid.client.DbService.getCustomers2()' threw an unexpected exception: java.lang.NoClassDefFoundError: com/extjs/gxt/samples/resources/client/model/Customer2
at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:378)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:581)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:207)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:243)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.NoClassDefFoundError: com/extjs/gxt/samples/resources/client/model/Customer2
at gwt.datgrid.server.DbServiceImpl.getCustomers2(DbServiceImpl.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
... 30 more