kospiotr
kospiotr

Reputation: 1867

Request factory generic method properties

Is it possible to use generics in Request methods? Or if not how to workaround this problem?

Lets say that I would like to implement pagination. So in my request interface I've got such method:

public List<UserProxy> getUserList(int offset, int limit);

but the list returns only limited data. For pagination implementation I need also total elements. In RPC style I would use Result object:

public MyResultObject<User> getUserList(int offset, int limit)

where in MyResultObject I would store List and totalCount as property. Unfortunately in RF I'm not able to that. Also in GWT-RPC I could use command pattern and retrive list from one method and totalcount from another one in a single request.

How to get totalcount with element list in the same time?

Upvotes: 5

Views: 927

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

You can have a MyResultObjectProxy (admittedly specialized for the UserProxy), or you can make your two requests (list and total count) in the same HTTP batch request:

MyContext ctx = factory.context();
ctx.getUserList(offset, limit).to(new Receiver<List<UserProxy>>() { … });
ctx.getUserTotalCount().to(new Receiver<Integer>() { … });
ctx.fire();

Since GWT 2.4, RF supports polymorphism, so maybe you could use a MyResultObjectProxy that's not specialized to a specific EntityProxy (or Value Proxy), though I'm really not sure it'd actually work.

Upvotes: 3

Related Questions