-
14 Nov 2011 3:30 AM #1
PaginLoader with a HttpProxy
PaginLoader with a HttpProxy
Hi!
I'm trying to do a JSON Paging Grid with the new version (3.0, pv5) and I'm merging both samples in the ExplorerSampleApplication (provided by Sencha), Json Grid Example and Paging Grid Example, but I can't create a simple PagingLoader. I'll provide parts of my sample code:
ReceiptData is a simple class with some sets and gets. The problem is that this code does not compile, it throws the following error:Code:HttpProxy<PagingLoadConfig> httpProxy = new HttpProxy<PagingLoadConfig>(requestBuilder); PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>>(httpProxy, reader);
The constructor PagingLoader<PagingLoadConfig,PagingLoadResult<ReceiptData>>(HttpProxy<PagingLoadConfig>, PolicyReceiptsViewPresenter.DataRecordJsonReader) is undefined
However if I change the Paging for the List, it works fine.
Anyway, when I try to add the module handler, it doesn't compile neither:Code:HttpProxy<ListLoadConfig> proxy = new HttpProxy<ListLoadConfig>(requestBuilder); ListLoader<ListLoadConfig, ListLoadResult<ReceiptData>> loader = new ListLoader<ListLoadConfig, ListLoadResult<ReceiptData>>(proxy, reader);
The error of the compiler:Code:LoaderHandler<ListLoadConfig, ListLoadResult<ReceiptData>> handler = new LoadResultListStoreBinding<ListLoadConfig, ReceiptData, ListLoadResult<ReceiptData>>(store);
Type mismatch: cannot convert from LoadResultListStoreBinding<ListLoadConfig,ReceiptData,ListLoadResult<ReceiptData>> to LoaderHandler<ListLoadConfig,ListLoadResult<ReceiptData>>
-
14 Nov 2011 6:50 AM #2
I think you've specified LoaderHandler when you meant LoadHandler. This is somewhat difficult to notice, and we may consider changing the name of one or both of the handler interfaces.
-
14 Nov 2011 7:09 AM #3
Aghh! It's true, I've spent a lot of time on the first problem and I haven't noticed about this evident error!
Sorry, and thanks a lot! Some suggestion about the first error?
Thanks in advance,
Marc.
-
14 Nov 2011 8:15 AM #4
Oops, missed the first one. It appears there may not be enough info to say - can you post the declaration and creation of the reader?
-
15 Nov 2011 12:04 AM #5
Hi Colin,
The code is adapted from your sample code (explorer, JSON Grid Example and Paging Grid Example):
The code to link the Proxy and the Reader with the grid:Code:public interface ReceiptDataAutoBeanFactory extends AutoBeanFactory { AutoBean<RecordResult> items(); AutoBean<ListLoadConfig> loadConfig(); } /** * Defines the structure of the root JSON object being returned by the server. * This class is needed as we cannot return a list of objects. Instead, we * return a single object with a single property that contains the data * records. */ public interface RecordResult { List<ReceiptData> getRecords(); } class DataRecordJsonReader extends JsonReader<ListLoadResult<ReceiptData>, RecordResult> { public DataRecordJsonReader(AutoBeanFactory factory, Class<RecordResult> rootBeanType) { super(factory, rootBeanType); } @Override protected ListLoadResult<ReceiptData> createReturnData(Object loadConfig, RecordResult incomingData) { return new BaseListLoadResult<ReceiptData>(incomingData.getRecords()); } }
I think that the problem is in DataProxy and not in reader.Code:RequestBuilder requestBuilder = RequestDataService.GetPolicyReceiptsRequestBuilder(policyId); ReceiptDataAutoBeanFactory factory = GWT.create(ReceiptDataAutoBeanFactory.class); DataRecordJsonReader reader = new DataRecordJsonReader(factory, RecordResult.class); ReceiptDataProperties properties = GWT.create(ReceiptDataProperties.class); ListStore<ReceiptData> store = new ListStore<ReceiptData>(properties.id()); HttpProxy<PagingLoadConfig> httpProxy = new HttpProxy<PagingLoadConfig>(requestBuilder); PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>>(httpProxy, reader); loader.useLoadConfig(factory.create(PagingLoadConfig.class).as()); loader.addLoadHandler(new LoadResultListStoreBinding<PagingLoadConfig, ReceiptData, PagingLoadResult<ReceiptData>>(store));
By the other hand, the code without pagination (ListLoader...) has worked fine!
Thanks a lot in advance,
Marc.
-
15 Nov 2011 3:42 AM #6
Sorry, effectively the problem was on the reader, I had defined it incorrectly. I'll try again to use pagination with a JSON source...
thanks a lot,
Marc.
-
22 Dec 2011 4:23 AM #7
The same problem
The same problem
Could you please advice me how can I use paging on the base of DataRecordJsonReader and HttpProxy classes from Ext GWT 3.0 beta1. Here is what I'm trying to do using Explorer Demo samples of JSON Grid and Paging Grid:
I'm not able to create PagingLoader on the base of my reader and proxy objects. Generic parameter types for PagingLoader creation require proxy and reader parametrized with a different number of types. I suppose there is some way to implement grid paging on base of HttpProxy that retrieves JSON but I can't find any documentation/tutorials related to this.Code:class DataRecordJsonReader extends JsonReader<ListLoadResult<IPoint>, RecordResult> { public DataRecordJsonReader(AutoBeanFactory factory, Class<RecordResult> rootBeanType) { super(factory, rootBeanType); } @Override protected ListLoadResult<IPoint> createReturnData(Object loadConfig, RecordResult incomingData) { return new ListLoadResultBean<IPoint>(incomingData.getRecords()); } } ... ListStore<IPoint> store = new ListStore<IPoint>(props.id()); JsonReader<ListLoadResult<IPoint>, RecordResult> reader = new DataRecordJsonReader(factory, RecordResult.class); HttpProxy<PagingLoadConfig> proxy = new HttpProxy<PagingLoadConfig>(builder); final PagingLoader<PagingLoadConfig, PagingLoadResult<IPoint>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<IPoint>>(proxy, reader); loader.setRemoteSort(true); loader.addLoadHandler(new LoadResultListStoreBinding<PagingLoadConfig, IPoint, ListLoadResult<IPoint>>(store));
-
22 Dec 2011 8:29 AM #8
I can't see which is exactly the problem but I fought a lot to solve the problem and I can't remember where was exactly my problem, so I give my code and I hope that it helps you:
And the createGrid function:Code:public interface ReceiptDataAutoBeanFactory extends AutoBeanFactory { AutoBean<RecordResult> items(); AutoBean<ListLoadConfig> loadConfig(); } /** * Defines the structure of the root JSON object being returned by the server. * This class is needed as we cannot return a list of objects. Instead, we * return a single object with a single property that contains the data * records. */ public interface RecordResult { List<ReceiptData> getRecords(); int getTotalCount(); } class DataRecordJsonReader extends JsonReader<PagingLoadResult<ReceiptData>, RecordResult> { public DataRecordJsonReader(AutoBeanFactory factory, Class<RecordResult> rootBeanType) { super(factory, rootBeanType); } @Override protected PagingLoadResult<ReceiptData> createReturnData(Object loadConfig, RecordResult incomingData) { PagingLoadConfig pagingLoadConfig = (PagingLoadConfig)loadConfig; List<ReceiptData> records = incomingData.getRecords();//.subList(pagingLoadConfig.getOffset(), pagingLoadConfig.getLimit()); return new BasePagingLoadResult<ReceiptData>(records, incomingData.getTotalCount(), pagingLoadConfig.getOffset()); } } ... public PolicyReceiptsViewPresenter(HandlerManager eventBus, int policyId) { super(eventBus); this.display = new PolicyReceiptsView(); RequestBuilder requestBuilder = RequestDataService.GetPolicyReceiptsRequestBuilder(policyId); // TODO No me funciona el paginado ReceiptDataAutoBeanFactory factory = GWT.create(ReceiptDataAutoBeanFactory.class); DataRecordJsonReader reader = new DataRecordJsonReader(factory, RecordResult.class); ReceiptDataProperties properties = GWT.create(ReceiptDataProperties.class); ListStore<ReceiptData> store = new ListStore<ReceiptData>(properties.id()); HttpProxy<PagingLoadConfig> httpProxy = new HttpProxy<PagingLoadConfig>(requestBuilder); PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>>( httpProxy, reader); loader.addLoadHandler(new LoadResultListStoreBinding<PagingLoadConfig, ReceiptData, PagingLoadResult<ReceiptData>>(store)); loader.setRemoteSort(true); Log.debug("attempt to create grid!"); this.display.createGrid(store, loader, properties); }
I remember that I had to force the loader (setReuseLoadConfig(true)) and cast manually with a warning the loader of the grid with the type that I know that it's.Code:public void createGrid(ListStore<ReceiptData> store, PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>> loader, ReceiptDataProperties properties) { final NumberFormat currency = NumberFormat.getCurrencyFormat(); final PagingToolBar toolBar = new PagingToolBar(10); toolBar.bind(loader); ... ColumnConfig... Grid<ReceiptData> view = new Grid<ReceiptData>(store, cm) { @Override protected void onAfterFirstAttach() { super.onAfterFirstAttach(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { loader.setReuseLoadConfig(true); PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>> currentLoader = (PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>>)loader; currentLoader.load(new RequestDataPagingLoadConfig()); // Realizamos la primera carga y mantenemos el LoadConfig establecido } }); } }; view.getView().setForceFit(true); view.setLoadMask(true); view.setLoader(loader); this.add(view, new VerticalLayoutData(1, 1)); this.add(toolBar, new VerticalLayoutData(1, -1)); }
Hope that it helps,
Marc.
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote