PDA

View Full Version : ClassCastException Bug in 2.0



jazzer
7 Jul 2009, 1:37 PM
Forgive me, I'm very new to Ext GWT. I'm trying to do a paging grid in 2.0. I think there is a casting issue w/ the 2.0 code.

In JSONReader.java, this method aways returns a List<ModelData>
protected Object createReturnData(Object loadConfig, List<ModelData> records,
int totalCount) {
return (D) records;
}

However BasePagingLoader is defined as:
public class BasePagingLoader<D extends PagingLoadResult<?>> extends BaseListLoader<D> implements PagingLoader<D> {

Where "D" extends PagingLoadResult. This leads to a class cast error with the following method in BasePagingLoader:

protected void onLoadSuccess(Object loadConfig, D result) {
LoadEvent evt = new LoadEvent(this, loadConfig, result);
totalCount = result.getTotalLength();
offset = result.getOffset();
fireEvent(Load, evt);
}

As the List<ModelData> returned from JSONReader to BaseLoader.java cannot be cast to "D extends PagingLoadResult" in BasePagingLoader.java (via BaseLoader.java's onSuccess(D result) method)

Please advise.

sven
7 Jul 2009, 1:40 PM
Moving this to the help forum. Take a look at the examples how to achieve this.

jazzer
8 Jul 2009, 3:53 AM
All of the examples use RPC - can you point to a 2.0 example for JSON? I think the bug is only for JSONreader + paging grid. The non paging grid works fine

sven
8 Jul 2009, 3:57 AM
The issue is in your code, you use the wrong jsonreander

jazzer
8 Jul 2009, 5:27 AM
Can you be more specific please...I tried three variations all based on the example code (which is for RPC), none of which worked. In each case I get a classcastexception. My code is below. Thanks again!

public class ResourceGridViewPaging extends LayoutContainer {

public ResourceGridViewPaging() {

}

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
FlowLayout layout = new FlowLayout(10);
setLayout(layout);

RequestBuilder objBuilder = new RequestBuilder(RequestBuilder.GET, "http://localhost:8080/rest/resourceStatus/listAll/json");

/* v 2.0 code */
HttpProxy<List<Resource>> proxy = new HttpProxy<List<Resource>>(objBuilder);
// HttpProxy<PagingLoadResult<Resource>> proxy = new HttpProxy<PagingLoadResult<Resource>>(objBuilder);


// I also tried various combinations like: JsonReader<List<Resource>>
JsonReader<PagingLoadResult<Resource>> objReader = new JsonReader<PagingLoadResult<Resource>>(Resource.getModelType())
{
@Override
protected ModelData newModelInstance() {
return new Resource();
}
@Override
protected Object createReturnData(Object objLoadConfig, List<ModelData> lstRecords, int intTotalCount) {
if (lstRecords.size() > 0) {
for (ModelData objItem : lstRecords) {
// cast items to resource and initialize if necessary
}
}
return lstRecords;
}
};

BasePagingLoader<PagingLoadResult<Resource>> loader =
new BasePagingLoader<PagingLoadResult<Resource>>(proxy, objReader);

loader.setRemoteSort(true);

loader.load(0, 50);


ListStore<Resource> store = new ListStore<Resource>(loader);
final PagingToolBar toolBar = new PagingToolBar(50);
toolBar.bind(loader);

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig(Resource.Fields.ID.toString(), "ID", 150));
columns.add(new ColumnConfig(Resource.Fields.NAME.toString(), "Name", 100));
columns.add(new ColumnConfig(Resource.Fields.DESC.toString(), "Description", 200));

ColumnModel cm = new ColumnModel(columns);

Grid<Resource> grid = new Grid<Resource>(store, cm);
grid.setLoadMask(true);
grid.setBorders(true);
grid.setAutoExpandColumn(Resource.Fields.DESC.toString());

ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setIconStyle("icon-table");
panel.setHeading("Paging Grid");
panel.setLayout(new FitLayout());
panel.add(grid);
panel.setSize(600, 350);
panel.setBottomComponent(toolBar);

add(panel);
}

}

jazzer
9 Jul 2009, 5:52 AM
Can anyone verify if this is a bug or an issue w/ my code? Ready to abandon ship...

sven
9 Jul 2009, 6:22 AM
You need to use the JsonLoadResultReader

jazzer
9 Jul 2009, 9:40 AM
I switched from JsonReader to JsonLoadResultReader (rest of the code is the same). No luck, same problem.

Jul 9, 2009 5:38:50 PM com.google.appengine.tools.development.LocalResourceFileServlet doGet
WARNING: No file found for: /none
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.extjs.gxt.ui.client.data.PagingLoadResult
at com.extjs.gxt.ui.client.data.BasePagingLoader.onLoadSuccess(BasePagingLoader.java:1)
at com.extjs.gxt.ui.client.data.BaseLoader$1.onSuccess(BaseLoader.java:127)
at com.extjs.gxt.ui.client.data.HttpProxy$1.onResponseReceived(HttpProxy.java:80)
at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264)
at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227)
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.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

sven
9 Jul 2009, 9:47 AM
Take a look at the examples. The sources are also avalaible.

http://www.extjs.com/examples/explorer.html#jsongrid

jazzer
9 Jul 2009, 10:05 AM
Thanks. I already have a working example of a non-paging grid with JsonLoader. The problem only occurs when I try a paging example. I have used both the Json Grid example and the RPC paging example as guides but have not been able to get this to work. What I really need is an example with a Json into a paging grid. I think this is a bug in the way gxt 2.0 implemented generics that leads to the class cast exception.

sven
9 Jul 2009, 10:20 AM
You should give us your latest code

jazzer
9 Jul 2009, 10:32 AM
Success. Sven, thanks for staying with me on this. The key was overriding the following method:

JsonLoadResultReader<ListLoadResult<ModelData>> objReader = new JsonLoadResultReader<ListLoadResult<ModelData>>(Resource.getModelType()) {
protected ListLoadResult<ModelData> newLoadResult(Object loadConfig, List<ModelData> models) {
return new BasePagingLoadResult<ModelData>(models);
}
};