Revision: 7654
Author: rj...@google.com
Date: Wed Mar  3 15:29:14 2010
Log: Added Values interface
http://code.google.com/p/google-web-toolkit/source/detail?r=7654

Modified:
 /wiki/RequestFactoryPlusPaths.wiki

=======================================
--- /wiki/RequestFactoryPlusPaths.wiki  Wed Mar  3 15:13:21 2010
+++ /wiki/RequestFactoryPlusPaths.wiki  Wed Mar  3 15:29:14 2010
@@ -29,15 +29,15 @@
     .to(myName));
 }}}

-Here's what's going on. {{{ ExpensesRequestFactory }}} is an interface generated by a JPA-aware tool that trawled through the server side domain classes. The user then GWT.create()s an instance of it. A request factory provides builders that can create request objects corresponding to every service method on the server side domain layer. +Here's what's going on. {{{ExpensesRequestFactory}}} is an interface generated by a JPA-aware tool that trawled through the server side domain classes. The user then GWT.create()s an instance of it. A request factory provides builders that can create request objects corresponding to every service method on the server side domain layer.

(The intention is that we provide the tool. Presumably we could provide similar tools for other persistence frameworks. JPA just happens to be a good choice for both Roo and GAE.)

-In this example, {{{ employees().findEmployee(e.getId()) }}} is creating an instance of a request object. That's important: findEmployee() isn't an rpc call, it's a factory call to create an instance of something like FindEmployeeRequest. Later on that will go over the wire to be interpreted by the server, probably as part of a batch at the end of the current eventloop.
-
-{{{ Employee }}} is another product of our tool, and embodies the id and properties of a server side entity class, e.g. {{{ Employee.DISPLAY_NAME }}}. See a full fledged example of it in the blip below.
-
-{{{ requests.values.subscribe() }}} is a call to {{{ ValueStore#subscribe(Path) }}}, which does the following: +In this example, {{{employees().findEmployee(e.getId())}}} is creating an instance of a request object. That's important: findEmployee() isn't an rpc call, it's a factory call to create an instance of something like FindEmployeeRequest. Later on that will go over the wire to be interpreted by the server, probably as part of a batch at the end of the current eventloop.
+
+{{{Employee}}} is another product of our tool, and embodies the id and properties of a server side entity class, e.g. {{{Employee.DISPLAY_NAME}}}. See a full fledged example of it in the blip below.
+
+{{{requests.values.subscribe()}}} is a call to {{{ValueStore#subscribe(Path)}}}, which does the following:

* It establishes a subscription keyed from the last entity + property of the path to an appropriate HasValue. In this case, myName is subscribed to Employee e's DISPLAY_NAME. * It fires off the request that anchors the path (findEmployee()) to ensure the necessary property value is available, perhaps short circuiting if such a call is already cached.
@@ -55,7 +55,6 @@
It's not hard to imagine an annotation that would cause the above to be generated. (Pretend GWT.create() has actually been made useful and now accepts helper arguments.)

 {{{
-
 class EmployeeDisplay extends Composite implements HasValue<Employee> {
   private static final UiBinder UI_BINDER =
     GWT.create(UiBinder.class, EmployeeDisplay.class);
@@ -73,34 +72,41 @@
     DATA_BINDER.setValue(this, values, value);
   }
 }
-
 }}}

Here's a more interesting path, to show someone's boss's name. Note that the subscription will keyed directly to the boss entity, not to the e.MANAGER.DISPLAY_NAME path.

 {{{
-
 HasValue<String> bossName = new TextField();

 requests.values.subscribe(e
   .newPathThrough(Employee.MANAGER)
   .through(Employee.DISPLAY_NAME)
   .to(bossName));
-
 }}}

For list values, we assume a HasValueList interface, which looks a lot like John L's ListHandler. (I'm cheating a bit, would really need both display name and id in the ListBox for this to be useful, but just to get the idea across):

 {{{
-
 HasValueList<String> employeeList = new ListBox();

 requests.values.subscribe(
   requests.employees().findAllEmployees()
     .forProperty(Employee.DISPLAY_NAME)
     .newPathTo(employeeList));
-
 }}}
+
+When you need more than just one field for an object (or object list), the Values<E> interface comes into play. It's basically a dedicated getter than can wrap any object managed by the value store:
+
+{{{
+HasValueList<Values<Employee>> employeeTable = new MyTableModel();
+
+requests.values.subscribe(
+  requests.employees().findAllEmployees()
+    .forProperty(Employee.DISPLAY_NAME)
+    .forProperty(Employee.USER_NAME)
+    .newPathTo(employeeTable));
+ }}}

 = Employee.java =

@@ -136,7 +142,6 @@
     return version;
   }
 }
-
 }}}

 = Entity.java =
@@ -160,3 +165,12 @@
 }
 }}}

+= Values.java =
+
+{{{
+public interface Values<E> {
+  E getEntity();
+
+  <V, P extends Property<E, V>> V get(P property);
+}
+}}}

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to