Revision: 6020
Author: jlaba...@google.com
Date: Thu Aug 27 09:07:32 2009
Log: Fixes a bug where FormPanel does not fire SubmitEvent when using a  
named frame (as opposed to a generated hidden iframe).

Patch by: t.broyer
Review by: jlabanca
Issue: 3973


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

Added:
   
/trunk/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue3973.java
Modified:
   
/trunk/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
  /trunk/user/src/com/google/gwt/user/client/ui/FormPanel.java
  /trunk/user/test/com/google/gwt/user/UISuite.java
  /trunk/user/test/com/google/gwt/user/client/ui/FormPanelTest.java

=======================================
--- /dev/null
+++  
/trunk/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue3973.java
       
Thu Aug 27 09:07:32 2009
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.museum.client.defaultmuseum;
+
+import com.google.gwt.museum.client.common.AbstractIssue;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.FormPanel;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
+import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
+
+/**
+ * When a {...@link FormPanel} does not use a synthesized hidden iframe and is
+ * being submit by means other than {...@link FormPanel#submit()}, it doesn't  
fire
+ * submit events.
+ */
+public class Issue3973 extends AbstractIssue {
+  private FormPanel form;
+
+  @Override
+  public Widget createIssue() {
+    form = new FormPanel("_blank");
+    form.setAction("http://www.google.com/search";);
+    form.addSubmitHandler(new SubmitHandler() {
+      public void onSubmit(SubmitEvent event) {
+        Window.alert("Did you see me?");
+        event.cancel();
+      }
+    });
+    TextBox box = new TextBox();
+    box.setName("q");
+    form.setWidget(box);
+    return form;
+  }
+
+  @Override
+  public String getInstructions() {
+    return "Enter some text and press the ENTER key, it should show an  
alert. It shouldn't open Google within a new window/tab!";
+  }
+
+  @Override
+  public String getSummary() {
+    return "FormPanel doesn't hook events when not using a synthesized  
hidden iframe.";
+  }
+
+  @Override
+  public boolean hasCSS() {
+    return false;
+  }
+}
=======================================
---  
/trunk/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
   
Fri Jun 12 15:33:13 2009
+++  
/trunk/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
   
Thu Aug 27 09:07:32 2009
@@ -49,6 +49,7 @@
      addIssue(new Issue2553());
      addIssue(new Issue2855());
      addIssue(new Issue3172());
+    addIssue(new Issue3973());
    }

    public void addVisuals() {
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/FormPanel.java        Fri Mar 
20  
11:33:42 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/FormPanel.java        Thu Aug 
27  
09:07:32 2009
@@ -569,24 +569,23 @@
        // Create and attach a hidden iframe to the body element.
        createFrame();
        Document.get().getBody().appendChild(synthesizedFrame);
-
-      // Hook up the underlying iframe's onLoad event when attached to the  
DOM.
-      // Making this connection only when attached avoids memory-leak  
issues.
-      // The FormPanel cannot use the built-in GWT event-handling mechanism
-      // because there is no standard onLoad event on iframes that works  
across
-      // browsers.
-      impl.hookEvents(synthesizedFrame, getElement(), this);
-    }
+    }
+    // Hook up the underlying iframe's onLoad event when attached to the  
DOM.
+    // Making this connection only when attached avoids memory-leak issues.
+    // The FormPanel cannot use the built-in GWT event-handling mechanism
+    // because there is no standard onLoad event on iframes that works  
across
+    // browsers.
+    impl.hookEvents(synthesizedFrame, getElement(), this);
    }

    @Override
    protected void onDetach() {
      super.onDetach();

-    if (synthesizedFrame != null) {
-      // Unhook the iframe's onLoad when detached.
-      impl.unhookEvents(synthesizedFrame, getElement());
-
+    // Unhook the iframe's onLoad when detached.
+    impl.unhookEvents(synthesizedFrame, getElement());
+
+    if (synthesizedFrame != null) {
        // And remove it from the document.
        Document.get().getBody().removeChild(synthesizedFrame);
        synthesizedFrame = null;
=======================================
--- /trunk/user/test/com/google/gwt/user/UISuite.java   Fri May 15 08:48:07  
2009
+++ /trunk/user/test/com/google/gwt/user/UISuite.java   Thu Aug 27 09:07:32  
2009
@@ -49,6 +49,7 @@
  import com.google.gwt.user.client.ui.FlexTableTest;
  import com.google.gwt.user.client.ui.FlowPanelTest;
  import com.google.gwt.user.client.ui.FocusPanelTest;
+import com.google.gwt.user.client.ui.FormPanelTest;
  import com.google.gwt.user.client.ui.GridTest;
  import com.google.gwt.user.client.ui.HTMLPanelTest;
  import com.google.gwt.user.client.ui.HiddenTest;
@@ -133,7 +134,7 @@
      suite.addTestSuite(FlexTableTest.class);
      suite.addTestSuite(FlowPanelTest.class);
      suite.addTestSuite(FocusPanelTest.class);
-    // suite.addTestSuite(FormPanelTest.class);
+    suite.addTestSuite(FormPanelTest.class);
      suite.addTestSuite(GridTest.class);
      suite.addTestSuite(HiddenTest.class);
      suite.addTestSuite(HistoryTest.class);
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/FormPanelTest.java   Thu  
Sep 18 12:31:46 2008
+++ /trunk/user/test/com/google/gwt/user/client/ui/FormPanelTest.java   Thu  
Aug 27 09:07:32 2009
@@ -18,9 +18,13 @@
  import com.google.gwt.core.client.GWT;
  import com.google.gwt.dom.client.Document;
  import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.InputElement;
  import com.google.gwt.junit.client.GWTTestCase;
  import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
+import com.google.gwt.user.client.ui.FormPanel.SubmitHandler;
  import com.google.gwt.user.client.ui.HasWidgetsTester.WidgetAdder;
+import com.google.gwt.user.server.ui.FormPanelTestServlet;

  /**
   * Tests the FormPanel.
@@ -161,6 +165,37 @@

      form.submit();
    }
+
+  public void testNamedTargetSubmitEvent() {
+    // Create a form and frame in the document we can wrap.
+    String uid = Document.get().createUniqueId();
+    HTML formAndFrame = new HTML(
+        "<form id='"
+            + uid
+            + "' method='post' target='targetFrame' action='"
+            + GWT.getModuleBaseURL()
+            + "formHandler?sendHappyHtml'>"
+            + "<input type='submit' id='submitBtn'></input></form>"
+            + "<iframe src='javascript:\'\'' id='targetMe'  
name='targetFrame'></iframe>");
+    RootPanel.get().add(formAndFrame);
+
+    // Wrap the form and make sure its target frame is intact.
+    FormPanel form = FormPanel.wrap(Document.get().getElementById(uid));
+    assertEquals("targetFrame", form.getTarget());
+
+    // Ensure that no synthesized iframe was created.
+    assertNull(form.getSynthesizedIFrame());
+
+    // Submit the form using the submit button and make sure the submit  
event fires.
+    delayTestFinish(5000);
+    form.addSubmitHandler(new SubmitHandler() {
+      public void onSubmit(SubmitEvent event) {
+        finishTest();
+      }
+    });
+
+     
Document.get().getElementById("submitBtn").<InputElement>cast().click();
+  }

    public void testReset() {
      FormPanel form = new FormPanel();

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

Reply via email to