質問

I am having difficulties understanding how my Service class should be written in order to implement GXT pagination with RequestFactory

I followed the example provided in the Demo site, as well as the javadoc example given in the Sencha website, but failed to completely understand both.

To start with let us say that my Service is returning List<Data> (Data is a server POJO) which needs to be loaded in a paginated fashion.

Here is my Service class which has exposed a pagination method

class BackendService {

   public List<Data> getData(int pageNumber, int pageSize) {
        int f = pageNumber * pageSize;
        int l = f + pageSize;
        if(f > 0 && l < datas.size()) {
            return  datas.subList(f, l);
        }
        return null;
   }
}

The RequestFactory looks like this

    @Service(value=BackendService.class, locator=BackendServiceLocator.class)
    interface BackendRequestContext extends RequestContext {

       Request<List<DataProxy>> getData(int pageNumber, int pageSize);

    }

    BackendRequestContext context();
}

The paging Grid is expecting a DataProxy implementation as follows

DataProxy<PagingLoadConfig, PagingLoadResult<com.emc.test.client.model.DataProxy>> proxy = new RequestFactoryProxy<PagingLoadConfig, PagingLoadResult<com.emc.test.client.model.DataProxy>>() {

            @Override
            public void load(PagingLoadConfig loadConfig, Receiver<? super PagingLoadResult<com.emc.test.client.model.DataProxy>> receiver) {
                int pageNum = loadConfig.getOffset();
                int pageSize = loadConfig.getLimit();
                Request<List<com.emc.test.client.model.DataProxy>> request = backendRequestFactory.context().getData(pageNum, pageSize);
                request.fire(receiver);
            }

};

In the above load method, this line is giving compilation error

request.fire(receiver);

because Receiver is expected to be

Receiver<? super PagingLoadResult<com.emc.test.client.model.DataProxy>>

Can anyone please help me regarding

  • how should I implement the service method?
  • Should i return PagingLoadResult instead of List from service itself? If yes how?

Thank you for your time on this thread!

役に立ちましたか?

解決

You need one more dto-proxy pair which extend PagingLoadResultBean/PagingLoadResult.

1) In backend part you have create the following dto:

public class YourCustomPagingLoadResultBean extends PagingLoadResultBean<Data> {

  protected YourCustomPagingLoadResultBean () {
  }

  public YourCustomPagingLoadResultBean (List<Data> list, int totalLength, int offset) {
    super(list, totalLength, offset);
  }
}

2) Create proxy for this dto:

@ProxyFor(YourCustomPagingLoadResultBean.class)
public interface YourCustomPagingLoadResultProxy extends ValueProxy, PagingLoadResult<DataProxy> {
  @Override
  List<DataProxy> getData();
}

3) Change you service to return paging bean:

public YourCustomPagingLoadResultBean getData(int pageNumber, int pageSize) {
  ...
  return new YourCustomPagingLoadResultBean(list, totalLength, offset);
}

4) Request also changes to:

Request<YourCustomPagingLoadResultProxy> getData(int pageNumber, int pageSize);

The DataProxy you are using looks correct, your paging grid will work after these 4 steps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top