【问题标题】:creating a GWT ValueProxy and sending to a service method创建 GWT ValueProxy 并发送到服务方法
【发布时间】:2011-02-24 23:47:04
【问题描述】:

我想使用 ValueProxy 参数调用服务上的方法 - 如果我执行 personProxy.setName("test") 然后 request.callFn(personProxy).fire(),则 name 属性不会传递给服务器。

我应该在设置名称或其他内容之前执行 request.edit(personProxy) 吗?

这是我正在使用的实现:

//somewhere in MyActivity.java ...
PersonProxy cp = requestFactory.myRequest().create(PersonProxy.class);
cp.setName("John Doe");
requestFactory.myRequest().doSomething(cp,"extra_param_value").fire(new Receiver<List<PersonProxy>>() {

    @Override
    public void onSuccess(List<PersonProxy> response) {
        //response from server...
    }

});

//------------------------
public interface MyRequestFactory extends RequestFactory {
    MyRequest myRequest();
}

//------------------------
@ServiceName(value="com.server.MyService", locator="com.server.MyServiceLocator")
public interface MyRequest extends RequestContext {
    public Request<Integer> doSomething(PersonProxy param, String extraParam);
}

//------------------------
public class MyServiceLocator implements ServiceLocator {

    public Object getInstance(Class<?> clazz) {
        return new MyService();
    }

}

//------------------------
public class MyService {
    public Integer doSomething(Person param, String extraParam) {
            System.out.println("person.name="+param.getName()); ---> prints NULL!!! why?
            return 0;
        }
}

//------------------------
@ProxyForName(value="com.server.Person")
public interface PersonProxy extends ValueProxy {
    String getName();
    void setName(String name);
}

//-----------------------
public class Person {
    public Person() {
        super();
    }

    protected String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

谢谢。

【问题讨论】:

    标签: gwt requestfactory


    【解决方案1】:

    PersonProxyRequestContext 的一个实例创建并在另一个实例中使用。原来AbstractRequestContext.retainArg() 中有一个错误应该引发异常来告诉您有关 API 的误用。可编辑代理不应该在不同的 RequestContext 实例之间可用。

    TreeRequest ctx = factory.treeRequest();
    PersonProxy person = ctx.create(PersonProxy.class);
    person.setName("John Doe");
    ctx.doSomething(person, "more stuff");
    

    正如在 IRC 上所讨论的,-Dgwt.rpc.dumpPayload=true JVM 标志可以在尝试诊断数据的去向(或不在)时打开。

    【讨论】:

    • 使用相同的 RequestContext 时,一切都完美无缺。谢谢!
    猜你喜欢
    • 2011-11-08
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 2011-09-16
    • 2019-10-03
    相关资源
    最近更新 更多