0

我正在使用 GWT RequestFactory 并希望在服务中传输客户端参数。参数应该在客户端创建,因为它们不是域模型的一部分,也不会存储在数据库中。不幸的是,我没有办法做到这一点,因为只有 xxxProxy 对象可以用作参数,并且它们只能在服务器上创建。

我的具体例子:

我想从服务器下载任务,并希望发送一个带有请求作为参数的过滤器对象,它指定要加载的任务对象。

谢谢你的帮助!

4

1 回答 1

3

您可以使用create()您的RequestContext. 在您的情况下,您的代理必须是ValueProxy而不是EntityProxy. 您不必“存储”值代理(与实体代理相反)。

我确实有和你完全相同的用例,而且效果很好。

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

作为旁注,您写了“只有 xxxProxy 对象可以用作参数”,这是错误的;您可以很好地使用原始类型(intboolean等)、它们的包装类型(IntegerBoolean等)、StringDateList/或Set它们(或代理类型)。

于 2011-09-15T08:03:51.980 回答