Revision: 7652
Author: rj...@google.com
Date: Wed Mar  3 15:11:02 2010
Log: Edited wiki page through web user interface.
http://code.google.com/p/google-web-toolkit/source/detail?r=7652

Modified:
 /wiki/RequestFactoryPlusPaths.wiki

=======================================
--- /wiki/RequestFactoryPlusPaths.wiki  Wed Mar  3 15:01:26 2010
+++ /wiki/RequestFactoryPlusPaths.wiki  Wed Mar  3 15:11:02 2010
@@ -35,131 +35,128 @@

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.
-Once we have the DISPLAY_NAME value, it is pushed to myName.setValue().
-Whenever e's DISPLAY_NAME is updated it is pushed again, until the subscription is dropped. +{{{ 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. + * Once we have the DISPLAY_NAME value, it is pushed to myName.setValue(). + * Whenever e's DISPLAY_NAME is updated it is pushed again, until the subscription is dropped.

If we can assume that every entity class has an appropriate findFoo() method, this can be simpler:

+{{{
 requests.values.subscribe(e
-.newPathThrough(Employee.DISPLAY_NAME)
-.to(myName));
+  .newPathThrough(Employee.DISPLAY_NAME)
+  .to(myName));
+}}}

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);
-private static final HasValueSupport DATA_BINDER =
-GWT.create(HasValueSupport.class, EmployeeDisplay.class);
-
-// works w/data binder b/c field name matches property
-// If it didn't match, could add @Path("displayName")
-...@uifield HasValue<String>displayName;
-
-private ValueStore values;
-
-public void setValueStore(ValueStore values) { this.values = values; }
-public void setValue(Employee value) {
-DATA_BINDER.setValue(this, values, value);
-}
+  private static final UiBinder UI_BINDER =
+    GWT.create(UiBinder.class, EmployeeDisplay.class);
+  private static final HasValueSupport DATA_BINDER =
+    GWT.create(HasValueSupport.class, EmployeeDisplay.class);
+
+  // works w/data binder b/c field name matches property
+  // If it didn't match, could add @Path("displayName")
+  @UiField HasValue<String>displayName;
+
+  private ValueStore values;
+
+  public void setValueStore(ValueStore values) { this.values = values; }
+  public void setValue(Employee value) {
+    DATA_BINDER.setValue(this, values, value);
+  }
 }

-Here's a more interesting path:
+}}}
+
+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));
+  .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));
-
-
-Employee.java
-
+  requests.employees().findAllEmployees()
+    .forProperty(Employee.DISPLAY_NAME)
+    .newPathTo(employeeList));
+
+}}}
+
+= Employee.java =
+
+{{{
 @ServerType(com.google.gwt.sample.valuebox.domain.Employee.class)
-
 public class Employee implements Entity {

-
-private final String id;
-
-private final Integer version;
-
-
-Employee(String id, Integer version) {
-
-this.id = id;
-
-this.version = version;
-
+  private final String id;
+  private final Integer version;
+
+  Employee(String id, Integer version) {
+    this.id = id;
+    this.version = version;
+  }
+
+  @javax.validation.constraints.Size(min = 2, max = 30)
+  public static final Property<Employee, String> USER_NAME =
+      new Property<Employee, String>(Employee.class, String.class);
+
+  @javax.validation.constraints.Size(min = 2, max = 30)
+  public static final Property<Employee, String> DISPLAY_NAME =
+      new Property<Employee, String>(Employee.class, String.class);
+
+  @javax.validation.constraints.NotNull
+  public static final Property<Employee, Employee> SUPERVISOR =
+      new Property<Employee, Employee>(Employee.class, Employee.class);
+
+  public String getId() {
+    return id;
+  }
+
+  public Integer getVersion() {
+    return version;
+  }
 }

-...@javax.validation.constraints.size(min = 2, max = 30)
-
-public static final Property<Employee, String> USER_NAME = new Property<Employee, String>(
-
-Employee.class, String.class);
-
-public static final Property<Employee, String> DISPLAY_NAME = new Property<Employee, String>(
-
-Employee.class, String.class);
-
-public static final Property<Employee, Employee> SUPERVISOR = new Property<Employee, Employee>(
-
-Employee.class, Employee.class);
-
-
-public String getId() {
-
-return id;
-
-}
-
-public Integer getVersion() {
-
-return version;
-
-}
-
-}
-
-Entity.java
-
+}}}
+
+= Entity.java =
+
+{{{
 public interface Entity {
-
-Object getId();
-
-Comparable<?> getVersion();
-
-}
-
-HasValueList.java
-
+  Object getId();
+  Comparable<?> getVersion();
+}
+}}}
+
+= HasValueList.java =
+
+{{{
 public interface HasValueList<V> {
-
-void editValueList(boolean replace, int index, List<V> newValues);
-
-void setValueList(List<V> newValues);
-
-void setValueListSize(int size, boolean exact); // @jlabanca: What does exact
-
-// mean?
-
-}
-
-
+  void editValueList(boolean replace, int index, List<V> newValues);
+  void setValueList(List<V> newValues);
+
+  // @jlabanca: What does exact mean?
+  void setValueListSize(int size, boolean exact);
+}
+}}}
+

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

Reply via email to