创建GWT ValueProxy并发送到服务方法
我想使用ValueProxy参数调用服务上的方法-如果我执行personProxy.setName(“测试”),然后请求.callFn(personProxy.fire(),则不会将name属性传递给服务器 我应该在设置名称或其他内容之前执行request.edit(personProxy)吗 这是我正在使用的实现:创建GWT ValueProxy并发送到服务方法,gwt,requestfactory,Gwt,Requestfactory,我想使用ValueProxy参数调用服务上的方法-如果我执行personProxy.setName(“测试”),然后请求.callFn(personProxy.fire(),则不会将name属性传递给服务器 我应该在设置名称或其他内容之前执行request.edit(personProxy)吗 这是我正在使用的实现: //somewhere in MyActivity.java ... PersonProxy cp = requestFactory.myRequest().create(Pers
//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;
}
}
//在MyActivity.java中的某个地方。。。
PersonProxy cp=requestFactory.myRequest().create(PersonProxy.class);
cp.setName(“John Doe”);
requestFactory.myRequest().doSomething(cp,“额外参数值”).fire(新接收器(){
@凌驾
成功时公共无效(列表响应){
//来自服务器的响应。。。
}
});
//------------------------
公共接口MyRequestFactory扩展了RequestFactory{
MyRequest MyRequest();
}
//------------------------
@ServiceName(value=“com.server.MyService”,locator=“com.server.MyServiceLocator”)
公共接口MyRequest扩展了RequestContext{
公共请求doSomething(PersonProxy参数、字符串extraParam);
}
//------------------------
公共类MyServiceLocator实现ServiceLocator{
公共对象getInstance(类clazz){
返回新的MyService();
}
}
//------------------------
公共类MyService{
公共整数doSomething(Person参数、String extraParam){
System.out.println(“person.name=“+param.getName());-->prints NULL!!!为什么?
返回0;
}
}
//------------------------
@ProxyForName(value=“com.server.Person”)
公共接口PersonProxy扩展了ValueProxy{
字符串getName();
void setName(字符串名);
}
//-----------------------
公共阶层人士{
公众人士(){
超级();
}
受保护的字符串名称;
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
}
谢谢。PersonProxy正在由一个
RequestContext
实例创建,并在另一个实例中使用。原来AbstractRequestContext.retainArg()
中有一个bug,它应该抛出一个异常来告诉您API误用的情况。可编辑代理不应该在不同的RequestContext
实例之间可用
TreeRequest ctx = factory.treeRequest();
PersonProxy person = ctx.create(PersonProxy.class);
person.setName("John Doe");
ctx.doSomething(person, "more stuff");
正如在IRC上所讨论的,当尝试诊断数据正在(或没有)去哪里时,可以打开JVM标志
-Dgwt.rpc.dumpPayload=true
。当使用相同的RequestContext时,一切工作都非常完美。非常感谢。