I´m using GWT RequestFactory and want to transport client-side parameters in a service. The parameters should be created on the client, because they aren´t part of the domain model and won´t be stored in the database. Unfortunately I found no way to do this, because only xxxProxy objects can be used as parameters and th开发者_开发技巧ey can only be created on the server.
My concrete example:
I want to download tasks from a server and want to send a filter object with the request as parameter, which specifies the task objects to be loaded.
Thanks for your help!
You can very-well create proxies on the client, using the create()
method of your RequestContext
. In your case, your proxy would have to be ValueProxy
rather than an EntityProxy
. You don't have to "store" value proxies (contrary to entity proxies).
I do have the exact same use case as yours, and it works very well.
@Service(MyService.class)
interface MyRequestContext extends RequestContext {
Request<List<TaskProxy>> findTasks(FilterProxy filter);
}
@ProxyFor(Filter.class)
interface FilterProxy extends ValueProxy {
// your getters and setters here
}
...
MyRequestContext ctx = ...;
FilterProxy filter = ctx.create(FilterProxy.class);
filter.setXxx(...);
// set your other filter
ctx.findTasks(filter).fire(new Receiver<List<TaskProxy>>() {
@Override
public void onSuccess(List<TaskProxy> tasks) {
// ...
}
});
As a side note, you wrote “only xxxProxy objects can be used as parameters”, which is wrong; you can very well use primitive types (int
, boolean
, etc.), their wrapper types (Integer
, Boolean
, etc.), String
, Date
, and List
or Set
of them (or proxy types).
精彩评论