RequestFactory Value Proxy Use Case

Skip to first unread message


Dec 27, 2011, 3:08:42 PM12/27/11
I am a little unclear as to how you use a Value Proxy (as opposed to an Entity Proxy) in RequestFactory.  I am assuming I can use it to do some server processing and return data back to the client?  But how do I do that?  I don't see a way to use a Locator, how do I populate the data in a Value Proxy?

Thanks for your help.

Patrick Julien

Dec 27, 2011, 8:52:10 PM12/27/11
A ValueProxy acts as a bridge to existing data types or objects that do get persisted but are outside your control, e.g., you can proxy a User from AppEngine to your client:

See the gwt expense sample.  It does exactly that, it uses a locator and a ValueProxy to expose GAE User's to the client.

Thomas Broyer

Dec 29, 2011, 6:27:10 AM12/29/11
The difference between ValueProxy and EntityProxy is that ValueProxy-s do not have "identity". Two EntityProxy-s can be said to represent the same object if they share the same stableId(); that cannot be said for ValueProxy, where each instance is a distinct object. For instance, when you RequestContext#edit() a ValueProxy, you create a clone. Another difference: ValueProxy-s are compared equals() by their properties' values. Obviously, while EntityProxy sends diffs of the modified properties from the client to the server, ValueProxy-s are always sent as a whole: there's nothing to diff against.

You can use a Locator with a ValueProxy, it's just that only the create() method will ever be called (so all other methods: find(), getId(), getVersion(), etc. should probably throw an UnsupportedOperationException). If your server-side class has a zero-arg constructor, then you don't need a Locator: being proxied by a ValueProxy, the requirements are different that from EntityProxy-s: no need for a static findXxx method, or getId or getVersion instance methods.

Apart from that, it works just like EntityProxy-s.

You can also see ValueProxy-s like the objects you'd transfer using GWT-RPC: when you send an object from client to server, or from server to client, you're making a "copy", created from scratch (with EntityProxy on the other hand, the "base object" could be retrieved from your database before being modified; with ValueProxy, a new instance is created each time).
If you're moving from GWT-RPC, I'd start using ValueProxy so your methods calls have the same semantics as with GWT-RPC, then move to EntityProxy if you want/need it.
Reply all
Reply to author
0 new messages