Revision: 9546
Author: b...@google.com
Date: Fri Jan 14 05:45:45 2011
Log: Integrate fix for issue 5752 into GWT 2.2 branch.
Don't flush RequestFactoryEditorDelegate when its associated request is locked.

http://code.google.com/p/google-web-toolkit/source/detail?r=9546

Modified:
/releases/2.2/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java /releases/2.2/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java

=======================================
--- /releases/2.2/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java Wed Dec 15 12:13:06 2010 +++ /releases/2.2/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java Fri Jan 14 05:45:45 2011
@@ -28,6 +28,7 @@
 import com.google.gwt.requestfactory.shared.RequestContext;
 import com.google.gwt.requestfactory.shared.RequestFactory;
 import com.google.gwt.requestfactory.shared.WriteOperation;
+import com.google.gwt.requestfactory.shared.impl.AbstractRequestContext;

 import java.util.ArrayList;
 import java.util.List;
@@ -93,7 +94,7 @@
        */
       return null;
     }
-
+
     if (!(getObject() instanceof EntityProxy)) {
       /*
        * This is kind of weird. The user is asking for notifications on a
@@ -136,6 +137,12 @@

   @Override
   protected boolean shouldFlush() {
-    return request != null;
+    if (request == null) {
+      return false;
+    }
+    if (request instanceof AbstractRequestContext) {
+      return !((AbstractRequestContext) request).isLocked();
+    }
+    return true;
   }
 }
=======================================
--- /releases/2.2/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java Wed Oct 6 10:46:19 2010 +++ /releases/2.2/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java Fri Jan 14 05:45:45 2011
@@ -52,14 +52,14 @@
   static class SimpleBarEditor implements Editor<SimpleBarProxy> {
     protected final SimpleEditor<String> userName = SimpleEditor.of();
   }
-
-  interface SimpleFooDriver extends
-      RequestFactoryEditorDriver<SimpleFooProxy, SimpleFooEditor> {
-  }

   static class SimpleFooBarOnlyEditor implements Editor<SimpleFooProxy> {
     SimpleBarEditor barField = new SimpleBarEditor();
   }
+
+  interface SimpleFooDriver extends
+      RequestFactoryEditorDriver<SimpleFooProxy, SimpleFooEditor> {
+  }

   static class SimpleFooEditor implements HasEditorErrors<SimpleFooProxy> {
     /**
@@ -162,6 +162,45 @@
     driver.edit(null, null);
     assertNull(editor.delegate.subscribe());
   }
+
+  /**
+ * Tests the editor can be re-used while the initial context is locked and
+   * therefore its attached proxies are frozen..
+   *
+   * @see http://code.google.com/p/google-web-toolkit/issues/detail?id=5752
+   */
+  public void testReuse() {
+    delayTestFinish(TEST_TIMEOUT);
+    final SimpleFooEditor editor = new SimpleFooEditor();
+
+    final SimpleFooDriver driver = GWT.create(SimpleFooDriver.class);
+    driver.initialize(req, editor);
+
+ req.simpleFooRequest().findSimpleFooById(1L).with(driver.getPaths()).fire(
+        new Receiver<SimpleFooProxy>() {
+          @Override
+          public void onSuccess(SimpleFooProxy response) {
+
+            SimpleFooRequest context = req.simpleFooRequest();
+            driver.edit(response, context);
+            editor.userName.setValue("One");
+            context.persistAndReturnSelf().using(response).with(
+                driver.getPaths()).to(new Receiver<SimpleFooProxy>() {
+              @Override
+              public void onSuccess(SimpleFooProxy response) {
+                assertEquals("One", response.getUserName());
+                // just testing that it doesn't throw (see issue 5752)
+                driver.edit(response, req.simpleFooRequest());
+                editor.userName.setValue("Two");
+                driver.flush();
+                finishTestAndReset();
+              }
+            });
+            // The fire() will freeze the proxies and lock the context
+            driver.flush().fire();
+          }
+        });
+  }

   public void testSubscription() {
     delayTestFinish(TEST_TIMEOUT);
@@ -171,7 +210,7 @@
     driver.initialize(req, editor);

     String[] paths = driver.getPaths();
-    assertEquals(Arrays.asList("barField.userName", "selfOneToManyField",
+    assertEquals(Arrays.asList("barField.userName", "selfOneToManyField",
         "selfOneToManyField.barField", "barField"), Arrays.asList(paths));

     req.simpleFooRequest().findSimpleFooById(1L).with(paths).fire(

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

Reply via email to