Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    mtomas is on a distinguished road

      0  

    Default 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:

    Code:
    HttpProxy<PagingLoadConfig> httpProxy = new HttpProxy<PagingLoadConfig>(requestBuilder);
    
    PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>> loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<ReceiptData>>(httpProxy, reader);
    ReceiptData is a simple class with some sets and gets. The problem is that this code does not compile, it throws the following error:
    The constructor PagingLoader<PagingLoadConfig,PagingLoadResult<ReceiptData>>(HttpProxy<PagingLoadConfig>, PolicyReceiptsViewPresenter.DataRecordJsonReader) is undefined

    However if I change the Paging for the List, it works fine.

    Code:
    HttpProxy<ListLoadConfig> proxy = new HttpProxy<ListLoadConfig>(requestBuilder);
    ListLoader<ListLoadConfig, ListLoadResult<ReceiptData>> loader = new ListLoader<ListLoadConfig, ListLoadResult<ReceiptData>>(proxy, reader);
    Anyway, when I try to add the module handler, it doesn't compile neither:
    Code:
    LoaderHandler<ListLoadConfig, ListLoadResult<ReceiptData>> handler = new LoadResultListStoreBinding<ListLoadConfig, ReceiptData, ListLoadResult<ReceiptData>>(store);
    The error of the compiler:
    Type mismatch: cannot convert from LoadResultListStoreBinding<ListLoadConfig,ReceiptData,ListLoadResult<ReceiptData>> to LoaderHandler<ListLoadConfig,ListLoadResult<ReceiptData>>

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    mtomas is on a distinguished road

      0  

    Default


    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.

  4. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    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?

  5. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    mtomas is on a distinguished road

      0  

    Default


    Hi Colin,

    The code is adapted from your sample code (explorer, JSON Grid Example and Paging Grid Example):
    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());
      }
     }
    The code to link the Proxy and the Reader with the grid:

    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));
    I think that the problem is in DataProxy and not in reader.

    By the other hand, the code without pagination (ListLoader...) has worked fine!

    Thanks a lot in advance,

    Marc.

  6. #6
    Sencha User
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    mtomas is on a distinguished road

      0  

    Default


    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.

  7. #7
    Sencha User
    Join Date
    Sep 2010
    Posts
    6
    Vote Rating
    0
    XGhost is on a distinguished road

      0  

    Default 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:

    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));
    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.

  8. #8
    Sencha User
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    mtomas is on a distinguished road

      0  

    Default


    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:

    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);
     }
    And the createGrid function:

    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));
     }
    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.

    Hope that it helps,

    Marc.