Dan L.
Dan L.

Reputation: 1747

creating a GWT ValueProxy and sending to a service method

I want to call a method on a Service with a ValueProxy param - if I do personProxy.setName("test") and then request.callFn(personProxy).fire(), the name property doesn't get passed to server.

Should I do a request.edit(personProxy) before setting the name or something else?

This is the implementation I'm using:

//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;
    }
}

Thanks.

Upvotes: 2

Views: 3246

Answers (1)

BobV
BobV

Reputation: 4173

The PersonProxy is being created by one instance of a RequestContext and used in another. Turns out there's a bug in AbstractRequestContext.retainArg() that should have thrown an exception to tell you about the API mis-use. Editable proxies aren't supposed to be usable between different RequestContext instances.

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

As discussed on IRC, the -Dgwt.rpc.dumpPayload=true JVM flag can be turned on when trying to diagnose where data is going (or isn't).

Upvotes: 6

Related Questions