I am trying to implement RequestFactory and the Editor framework into my app. I\'m finding even after researching the forum, the Google Developer forum, and others that there is
Take a look at the RequestFactoryTest in the GWT source code for examples. The testChangedEdit() method is similar to what you're trying to write. It calls a find()
method and then operates on the returned proxy in the onSuccess()
method.
A RequestContext
isn't a long-lived object. It is only valid from the time that it is called to when you call fire()
on it. It can be re-used only if the onFailure()
or onViolation()
method is called in your Receiver
.
An EntityProxy
or ValueProxy
returned via Receiver.onSuccess()
represents a snapshot of server data. Thus, the proxy is immutable unless it is associated with a RequestContext
by calling edit()
. The proxies returned by RequestContext.create()
are mutable. A mutable proxy is always associated with exactly one RequestContext
and it is an error to "cross the streams." It is not an error to re-edit()
a mutable proxy.
The reason it works this way is to allow the RequestFactory client to only send deltas to the server. The deltas are applied to the long-lived entities on the server by calling the domain object's find()
method (or using a Locator
). The RequestContext is essentially an accumulator for proxy.setFoo()
calls and one or more Request
/ InstanceRequest
invocations.
General guidelines:
fire()
method invocation.EntityProxy
or ValueProxy
instances should not be retained beyond the call to fire()
.EntityProxyId
returned from EntityProxy.stableId()
can be retained indefinitely, even from a newly-created proxy. The stableId
object is suitable for use as the key in Map
objects and has stable object-identity semantics (i.e. two snapshots of the same server domain object with different versions would return the same `EntityProxyId').RequestFactory
should be constructed once and retained for the lifetime of the module, since they have non-trivial construction cost.