Vanquish59
4 Jan 2012, 4:30 PM
Hi guys, new to the forum, hello to all.
Having a problem loading data with RPC pagination with GXT.
I'm loading a paginated grid with Account objects in a ListStore.
Problem: Data doesn't load into this grid. I see the grid, I see the toolbar on the button, and I see the number of objects that are in the toolbar. I added 7 objects and on the toolbar it says Display 1-3 of 7, but with no data.
Here is the Account class
public class Account implements Serializable, BeanModelTag
{
private Long id;
private String type;
private double balance;
public Account()
{
}
public Account(Long id, String type, double balance)
{
this.id = id;
this.type = type;
this.balance = balance;
}
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public double getBalance()
{
return balance;
}
public void setBalance(double balance)
{
this.balance = balance;
}
}
Here is the AccountService
@RemoteServiceRelativePath("AccountService")
public interface AccountService extends RemoteService
{
public List<Account> getAccounts();
public PagingLoadResult<Account> getPagedAccounts(final PagingLoadConfig config);
}
Here is AccountServiceAsync
public interface AccountServiceAsync
{
void getAccounts(AsyncCallback<List<Account>> async);
void getPagedAccounts(final PagingLoadConfig config, AsyncCallback<PagingLoadResult<Account>> async);
}
Here is AccountServiceImpl
public class AccountServiceImpl extends RemoteServiceServlet implements AccountService
{
private List<Account> accounts = new ArrayList<Account>();
public List<Account> getAccounts()
{
Account a = new Account(Long.valueOf("1"), "Checking", 38915.35);
Account b = new Account(Long.valueOf("2"), "Savings", 450000.35);
Account c = new Account(Long.valueOf("3"), "Checking", 175.25);
Account d = new Account(Long.valueOf("4"), "Checking", 551525.39);
Account e = new Account(Long.valueOf("5"), "Savings", 1525.45);
Account f = new Account(Long.valueOf("6"), "Savings", 12.25);
Account g = new Account(Long.valueOf("7"), "Checking", 173535.25);
accounts.add(a);
accounts.add(b);
accounts.add(c);
accounts.add(d);
accounts.add(e);
accounts.add(f);
accounts.add(g);
return accounts;
}
public PagingLoadResult<Account> getPagedAccounts(PagingLoadConfig config)
{
List<Account> accs = new ArrayList<Account>();
Account a = new Account(Long.valueOf("1"), "Checking", 38915.35);
Account b = new Account(Long.valueOf("2"), "Savings", 450000.35);
Account c = new Account(Long.valueOf("3"), "Checking", 175.25);
Account d = new Account(Long.valueOf("4"), "Checking", 551525.39);
Account e = new Account(Long.valueOf("5"), "Savings", 1525.45);
Account f = new Account(Long.valueOf("6"), "Savings", 12.25);
Account g = new Account(Long.valueOf("7"), "Checking", 173535.25);
accs.add(a);
accs.add(b);
accs.add(c);
accs.add(d);
accs.add(e);
accs.add(f);
accs.add(g);
return getPagingLoadResult(accs, config);
}
private PagingLoadResult<Account> getPagingLoadResult(List<Account> accs, PagingLoadConfig config)
{
List<Account> pagedAccounts = new ArrayList<Account>();
int start = config.getOffset();
int limit = accs.size();
if(config.getLimit() > 0)
{
limit = Math.min(start + config.getLimit(), limit);
}
for(int i = config.getOffset(); i<limit; i++)
{
pagedAccounts.add(accs.get(i));
}
return new BasePagingLoadResult<Account>(pagedAccounts, config.getOffset(), accs.size());
}
}
Here is the class that sets the grid...
public class EastNavigationPanel extends ContentPanel
{
public EastNavigationPanel()
{
setHeading("East");
setWidth(250);
setLayout(new FitLayout());
//add(new AccountGrid_RPC_WITH_PROXY());
final AccountServiceAsync aService = GWT.create(AccountService.class);
RpcProxy proxy = new RpcProxy()
{
@Override
protected void load(Object o, AsyncCallback asyncCallback)
{
aService.getPagedAccounts((PagingLoadConfig)o, asyncCallback);
}
};
PagingLoader loader = new BasePagingLoader(proxy);
loader.load();
final PagingToolBar bar = new PagingToolBar(3);
bar.bind(loader);
List<ColumnConfig> cols = new ArrayList<ColumnConfig>();
ColumnConfig id = new ColumnConfig("id", "Id", 150);
ColumnConfig type = new ColumnConfig("type", "Type", 150);
ColumnConfig balance = new ColumnConfig("balance", "Balance", 150);
cols.add(id);
cols.add(type);
cols.add(balance);
final ColumnModel cm = new ColumnModel(cols);
Grid<BeanModel> grid = new Grid<BeanModel>(models, cm);
grid.setBorders(true);
grid.setStripeRows(true);
grid.setStyleAttribute("borderTop", "none");
grid.setAutoExpandColumn("balance");
GridSelectionModel gsm = grid.getSelectionModel();
gsm.setSelectionMode(Style.SelectionMode.SINGLE);
setBottomComponent(bar);
add(grid);
}
}
Here is the exception I get. Looks trivial, but I'm confused where it's being thrown...
ERROR: Uncaught exception escaped. java.lang.ClassCastException: com.mySampleApplication.client.model.Account cannot be cast to com.extjs.gxt.ui.client.data.ModelData
at com.extjs.gxt.ui.client.store.ListStore.getAt(ListStore.java:208)
at com.extjs.gxt.ui.client.store.ListStore.getRange(ListStore.java:248)
at com.extjs.gxt.ui.client.widget.grid.GridView.renderRows(GridView.java:1796)
at com.extjs.gxt.ui.client.widget.grid.GroupingView.renderRows(GroupingView.java:503)
at com.extjs.gxt.ui.client.widget.grid.GridView.afterRender(GridView.java:703)
at com.extjs.gxt.ui.client.widget.grid.Grid.afterRenderView(Grid.java:722)
at com.extjs.gxt.ui.client.widget.grid.Grid$1.run(Grid.java:711)
at com.google.gwt.user.client.Timer.fire(Timer.java:149)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)
ERROR: Uncaught exception escaped. java.lang.ClassCastException: com.mySampleApplication.client.model.Account cannot be cast to com.extjs.gxt.ui.client.data.ModelData
at com.extjs.gxt.ui.client.store.ListStore.getAt(ListStore.java:208)
at com.extjs.gxt.ui.client.store.ListStore.getRange(ListStore.java:248)
at com.extjs.gxt.ui.client.widget.grid.GridView.renderRows(GridView.java:1796)
at com.extjs.gxt.ui.client.widget.grid.GridView.afterRender(GridView.java:703)
at com.extjs.gxt.ui.client.widget.grid.Grid.afterRenderView(Grid.java:722)
at com.extjs.gxt.ui.client.widget.grid.Grid$1.run(Grid.java:711)
at com.google.gwt.user.client.Timer.fire(Timer.java:149)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)
Thanks guys.
Having a problem loading data with RPC pagination with GXT.
I'm loading a paginated grid with Account objects in a ListStore.
Problem: Data doesn't load into this grid. I see the grid, I see the toolbar on the button, and I see the number of objects that are in the toolbar. I added 7 objects and on the toolbar it says Display 1-3 of 7, but with no data.
Here is the Account class
public class Account implements Serializable, BeanModelTag
{
private Long id;
private String type;
private double balance;
public Account()
{
}
public Account(Long id, String type, double balance)
{
this.id = id;
this.type = type;
this.balance = balance;
}
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public double getBalance()
{
return balance;
}
public void setBalance(double balance)
{
this.balance = balance;
}
}
Here is the AccountService
@RemoteServiceRelativePath("AccountService")
public interface AccountService extends RemoteService
{
public List<Account> getAccounts();
public PagingLoadResult<Account> getPagedAccounts(final PagingLoadConfig config);
}
Here is AccountServiceAsync
public interface AccountServiceAsync
{
void getAccounts(AsyncCallback<List<Account>> async);
void getPagedAccounts(final PagingLoadConfig config, AsyncCallback<PagingLoadResult<Account>> async);
}
Here is AccountServiceImpl
public class AccountServiceImpl extends RemoteServiceServlet implements AccountService
{
private List<Account> accounts = new ArrayList<Account>();
public List<Account> getAccounts()
{
Account a = new Account(Long.valueOf("1"), "Checking", 38915.35);
Account b = new Account(Long.valueOf("2"), "Savings", 450000.35);
Account c = new Account(Long.valueOf("3"), "Checking", 175.25);
Account d = new Account(Long.valueOf("4"), "Checking", 551525.39);
Account e = new Account(Long.valueOf("5"), "Savings", 1525.45);
Account f = new Account(Long.valueOf("6"), "Savings", 12.25);
Account g = new Account(Long.valueOf("7"), "Checking", 173535.25);
accounts.add(a);
accounts.add(b);
accounts.add(c);
accounts.add(d);
accounts.add(e);
accounts.add(f);
accounts.add(g);
return accounts;
}
public PagingLoadResult<Account> getPagedAccounts(PagingLoadConfig config)
{
List<Account> accs = new ArrayList<Account>();
Account a = new Account(Long.valueOf("1"), "Checking", 38915.35);
Account b = new Account(Long.valueOf("2"), "Savings", 450000.35);
Account c = new Account(Long.valueOf("3"), "Checking", 175.25);
Account d = new Account(Long.valueOf("4"), "Checking", 551525.39);
Account e = new Account(Long.valueOf("5"), "Savings", 1525.45);
Account f = new Account(Long.valueOf("6"), "Savings", 12.25);
Account g = new Account(Long.valueOf("7"), "Checking", 173535.25);
accs.add(a);
accs.add(b);
accs.add(c);
accs.add(d);
accs.add(e);
accs.add(f);
accs.add(g);
return getPagingLoadResult(accs, config);
}
private PagingLoadResult<Account> getPagingLoadResult(List<Account> accs, PagingLoadConfig config)
{
List<Account> pagedAccounts = new ArrayList<Account>();
int start = config.getOffset();
int limit = accs.size();
if(config.getLimit() > 0)
{
limit = Math.min(start + config.getLimit(), limit);
}
for(int i = config.getOffset(); i<limit; i++)
{
pagedAccounts.add(accs.get(i));
}
return new BasePagingLoadResult<Account>(pagedAccounts, config.getOffset(), accs.size());
}
}
Here is the class that sets the grid...
public class EastNavigationPanel extends ContentPanel
{
public EastNavigationPanel()
{
setHeading("East");
setWidth(250);
setLayout(new FitLayout());
//add(new AccountGrid_RPC_WITH_PROXY());
final AccountServiceAsync aService = GWT.create(AccountService.class);
RpcProxy proxy = new RpcProxy()
{
@Override
protected void load(Object o, AsyncCallback asyncCallback)
{
aService.getPagedAccounts((PagingLoadConfig)o, asyncCallback);
}
};
PagingLoader loader = new BasePagingLoader(proxy);
loader.load();
final PagingToolBar bar = new PagingToolBar(3);
bar.bind(loader);
List<ColumnConfig> cols = new ArrayList<ColumnConfig>();
ColumnConfig id = new ColumnConfig("id", "Id", 150);
ColumnConfig type = new ColumnConfig("type", "Type", 150);
ColumnConfig balance = new ColumnConfig("balance", "Balance", 150);
cols.add(id);
cols.add(type);
cols.add(balance);
final ColumnModel cm = new ColumnModel(cols);
Grid<BeanModel> grid = new Grid<BeanModel>(models, cm);
grid.setBorders(true);
grid.setStripeRows(true);
grid.setStyleAttribute("borderTop", "none");
grid.setAutoExpandColumn("balance");
GridSelectionModel gsm = grid.getSelectionModel();
gsm.setSelectionMode(Style.SelectionMode.SINGLE);
setBottomComponent(bar);
add(grid);
}
}
Here is the exception I get. Looks trivial, but I'm confused where it's being thrown...
ERROR: Uncaught exception escaped. java.lang.ClassCastException: com.mySampleApplication.client.model.Account cannot be cast to com.extjs.gxt.ui.client.data.ModelData
at com.extjs.gxt.ui.client.store.ListStore.getAt(ListStore.java:208)
at com.extjs.gxt.ui.client.store.ListStore.getRange(ListStore.java:248)
at com.extjs.gxt.ui.client.widget.grid.GridView.renderRows(GridView.java:1796)
at com.extjs.gxt.ui.client.widget.grid.GroupingView.renderRows(GroupingView.java:503)
at com.extjs.gxt.ui.client.widget.grid.GridView.afterRender(GridView.java:703)
at com.extjs.gxt.ui.client.widget.grid.Grid.afterRenderView(Grid.java:722)
at com.extjs.gxt.ui.client.widget.grid.Grid$1.run(Grid.java:711)
at com.google.gwt.user.client.Timer.fire(Timer.java:149)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)
ERROR: Uncaught exception escaped. java.lang.ClassCastException: com.mySampleApplication.client.model.Account cannot be cast to com.extjs.gxt.ui.client.data.ModelData
at com.extjs.gxt.ui.client.store.ListStore.getAt(ListStore.java:208)
at com.extjs.gxt.ui.client.store.ListStore.getRange(ListStore.java:248)
at com.extjs.gxt.ui.client.widget.grid.GridView.renderRows(GridView.java:1796)
at com.extjs.gxt.ui.client.widget.grid.GridView.afterRender(GridView.java:703)
at com.extjs.gxt.ui.client.widget.grid.Grid.afterRenderView(Grid.java:722)
at com.extjs.gxt.ui.client.widget.grid.Grid$1.run(Grid.java:711)
at com.google.gwt.user.client.Timer.fire(Timer.java:149)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor46.invoke(Unknown Source)
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.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:662)
Thanks guys.