GWT Request Factory - Create and persist object - Should proxy automatically be populated with id?

StackOverflow https://stackoverflow.com/questions/16990518

  •  31-05-2022
  •  | 
  •  

質問

If i create a proxy object on the client side and persist it, shouldn't my proxy object after it is persisted on the server side be automatically updated with the generated id?

For example this code prints out "null".

final MyRequestFactory requestFactory = clientFactory.getRequestFactory();
final TestRequest request = requestFactory.testRequest();

final TestProxy myTestObj = request.create(TestProxy.class);

Request<Void> createReq = request.persist.using(myTestObj);

createReq.fire(new Receiver<Void>() {
    @Override
    public void onSuccess(Void nothing) {
        System.out.println(myTestObj.getId());
    }
});

Or do i have to change my code so that the persist method returns my object again?

役に立ちましたか?

解決

Yes, you are right, calling persist() does not change the proxy object in the client, you have to go to the server to get the object again.

The normal way is to define a persistAndReturnSelf() method in your Request.

request.persistAndReturnSelf(myTestObj).fire(new Receiver<TestProxy>()) {
   ...
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top