Integrate fix for issue 5752 into GWT 2.2 branch. Don't flush RequestFactoryEditorDelegate when its associated request is locked. git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/2.2@9546 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java b/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java index 26fc76c..55b1ae3 100644 --- a/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java +++ b/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java
@@ -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; } }
diff --git a/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java b/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java index d9b71ae..e2b7ecd 100644 --- a/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java +++ b/user/test/com/google/gwt/requestfactory/client/ui/EditorTest.java
@@ -53,14 +53,14 @@ 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> { /** * Test field-based access. @@ -163,6 +163,45 @@ 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); final SimpleFooEditorWithDelegate editor = new SimpleFooEditorWithDelegate(); @@ -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(