You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/09/07 23:46:19 UTC

svn commit: r1166423 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/corelib/components/ main/java/org/apache/tapestry5/internal/ main/resources/org/apache/tapestry5/ test/app1/ test/groovy/org/apache/tapestry5/integrat...

Author: hlship
Date: Wed Sep  7 21:46:19 2011
New Revision: 1166423

URL: http://svn.apache.org/viewvc?rev=1166423&view=rev
Log:
TAP5-1632: When a submit component does not have a specific id, the default id "submit" collides ont the client side with the HTMLFormElement.submit() method, causing JavaScript errors when the form is submitted

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/CanceledEventDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/CanceledEventTests.groovy
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/CanceledEventDemo.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalSymbols.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java?rev=1166423&r1=1166422&r2=1166423&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java Wed Sep  7 21:46:19 2011
@@ -49,22 +49,22 @@ import java.io.ObjectInputStream;
  * An HTML form, which will enclose other components to render out the various
  * types of fields.
  * <p>
- * A Form emits many notification events. When it renders, it fires a
+ * A Form triggers many notification events. When it renders, it triggers a
  * {@link org.apache.tapestry5.EventConstants#PREPARE_FOR_RENDER} notification, followed by a
  * {@link EventConstants#PREPARE} notification.</p>
  * <p>
- * When the form is submitted, the component emits several notifications: first a
+ * When the form is submitted, the component triggers several notifications: first a
  * {@link EventConstants#PREPARE_FOR_SUBMIT}, then a {@link EventConstants#PREPARE}: these allow the page to update its
  * state as necessary to prepare for the form submission.</p>
  * <p>
- * The Form component determines if the form was cancelled (see {@link org.apache.tapestry5.corelib.SubmitMode#CANCEL}. If so,
- * an {@link EventConstants#CANCELED} event is emitted.</p>
+ * The Form component then determines if the form was cancelled (see {@link org.apache.tapestry5.corelib.SubmitMode#CANCEL}). If so,
+ * a {@link EventConstants#CANCELED} event is triggered.</p>
  * <p>
  * Next come notifications to contained components (or more accurately, the execution of stored {@link ComponentAction}s), to allow each component to retrieve and validate
  * submitted values, and update server-side properties.  This is based on the {@code t:formdata} query parameter,
  * which contains serialized object data (generated when the form initially renders).
  * </p>
- * <p>Once the form data is processed, the next step is to emit the
+ * <p>Once the form data is processed, the next step is to trigger the
  * {@link EventConstants#VALIDATE}, which allows for cross-form validation. After that, either a
  * {@link EventConstants#SUCCESS} OR {@link EventConstants#FAILURE} event (depending on whether the
  * {@link ValidationTracker} has recorded any errors). Lastly, a {@link EventConstants#SUBMIT} event, for any listeners
@@ -87,7 +87,7 @@ import java.io.ObjectInputStream;
  */
 @Events(
         {EventConstants.PREPARE_FOR_RENDER, EventConstants.PREPARE, EventConstants.PREPARE_FOR_SUBMIT,
-                EventConstants.VALIDATE, EventConstants.SUBMIT, EventConstants.FAILURE, EventConstants.SUCCESS})
+                EventConstants.VALIDATE, EventConstants.SUBMIT, EventConstants.FAILURE, EventConstants.SUCCESS, EventConstants.CANCELED})
 public class Form implements ClientElement, FormValidationControl
 {
     /**
@@ -729,6 +729,9 @@ public class Form implements ClientEleme
         for (String name : TapestryInternalUtils.splitAtCommas(preselectedFormNames))
         {
             idAllocator.allocateId(name);
+            // See https://issues.apache.org/jira/browse/TAP5-1632
+            javascriptSupport.allocateClientId(name);
+
         }
 
         Component activePage = componentSource.getActivePage();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java?rev=1166423&r1=1166422&r2=1166423&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java Wed Sep  7 21:46:19 2011
@@ -166,6 +166,11 @@ public class LinkSubmit implements Clien
 
             spec.put("validate", mode == SubmitMode.NORMAL);
 
+            if (mode == SubmitMode.CANCEL)
+            {
+                spec.put("cancel", true);
+            }
+
             javascriptSupport.addInitializerCall(InitializationPriority.EARLY, "linkSubmit", spec);
         }
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalSymbols.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalSymbols.java?rev=1166423&r1=1166422&r2=1166423&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalSymbols.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalSymbols.java Wed Sep  7 21:46:19 2011
@@ -25,15 +25,16 @@ public class InternalSymbols
     /**
      * The application package converted to a path ('.' becomes '/'). Useful for finding resources
      * on the classpath relevant to the application.
-     * 
+     *
      * @since 5.1.0.0
      */
     public static final String APP_PACKAGE_PATH = "tapestry.app-package-path";
 
     /**
      * Comma-separated list of pre-allocated Form component control names. Basically, this exists to
-     * work around name collisions on the client side.
-     * 
+     * work around name collisions on the client side. Starting in 5.3, these names are
+     * also pre-allocated as ids.
+     *
      * @since 5.2.0
      */
     public static final String PRE_SELECTED_FORM_NAMES = "tapestry.pre-selected-form-names";

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js?rev=1166423&r1=1166422&r2=1166423&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js Wed Sep  7 21:46:19 2011
@@ -663,7 +663,9 @@ Element.addMethods({
      */
     isDeepVisible : function(element, options) {
         var current = $(element);
-        var boundFunc = (options && options.bound) || function(el) { return el.tagName == "FORM"};
+        var boundFunc = (options && options.bound) || function(el) {
+            return el.tagName == "FORM"
+        };
 
         while (true) {
             if (!current.visible())
@@ -980,6 +982,10 @@ T5.extendInitializers({
 
         $(spec.clientId).writeAttribute("href", "#");
 
+        if (spec.cancel) {
+            $(spec.clientId).writeAttribute("name", "cancel");
+        }
+
         $(spec.clientId).observeAction("click", function(event) {
 
             var form = $(spec.form);
@@ -1046,7 +1052,7 @@ T5.extendInitializers({
             /*
              * After the form is validated and prepared, this code will
              * process the form submission via an Ajax call. The
-             * original submit event will have been cancelled.
+             * original submit event wilpl have been cancelled.
              */
 
             element

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/CanceledEventDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/CanceledEventDemo.tml?rev=1166423&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/CanceledEventDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/CanceledEventDemo.tml Wed Sep  7 21:46:19 2011
@@ -0,0 +1,16 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+<h1>Canceled Event Demo</h1>
+
+<t:form t:id="form">
+    <t:errors/>
+    <t:label for="requiredText"/>
+    <t:textfield t:id="requiredText"/>
+
+    <br/>
+
+    <t:submit mode="cancel" value="Cancel Form"/>
+    <t:linksubmit mode="cancel">Cancel Form</t:linksubmit>
+
+</t:form>
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/CanceledEventTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/CanceledEventTests.groovy?rev=1166423&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/CanceledEventTests.groovy (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/CanceledEventTests.groovy Wed Sep  7 21:46:19 2011
@@ -0,0 +1,27 @@
+package org.apache.tapestry5.integration.app1
+
+import org.apache.tapestry5.integration.TapestryCoreTestCase
+import org.testng.annotations.Test
+
+class CanceledEventTests extends TapestryCoreTestCase
+{
+    @Test
+    void cancel_button()
+    {
+        openLinks "Canceled Event Demo"
+
+        clickAndWait SUBMIT
+
+        assertText "css=.t-alert-container", "Form was canceled."
+    }
+
+    @Test
+    void cancel_link()
+    {
+        openLinks "Canceled Event Demo"
+
+        clickAndWait "link=Cancel Form"
+
+        assertText "css=.t-alert-container", "Form was canceled."
+    }
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java?rev=1166423&r1=1166422&r2=1166423&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java Wed Sep  7 21:46:19 2011
@@ -274,7 +274,7 @@ public class FormTests extends TapestryC
         waitForCondition(selectedGoneCondition, PAGE_LOAD_TIMEOUT);
 
         click("xpath=//td[text()='28']");
-        String pickerGoneSelector="css=div.datePicker";
+        String pickerGoneSelector = "css=div.datePicker";
         waitForInvisible(pickerGoneSelector);
 
         assertFieldValue("asteroidImpact", "6/28/2035");
@@ -423,6 +423,8 @@ public class FormTests extends TapestryC
     {
         openLinks("Disabled Fields");
 
+        // The couple of places where there's a _0 suffix is related to
+        // the fix for https://issues.apache.org/jira/browse/TAP5-1632
         String[] paths = new String[]
                 {"//input[@id='textfield']",
 
@@ -432,7 +434,7 @@ public class FormTests extends TapestryC
 
                         "//input[@id='checkbox']",
 
-                        "//select[@id='select']",
+                        "//select[@id='select_0']",
 
                         "//input[@id='radio1']",
 
@@ -448,7 +450,7 @@ public class FormTests extends TapestryC
 
                         "//select[@id='palette']",
 
-                        "//input[@id='submit']"};
+                        "//input[@id='submit_0']"};
 
         for (String path : paths)
         {

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/CanceledEventDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/CanceledEventDemo.java?rev=1166423&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/CanceledEventDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/CanceledEventDemo.java Wed Sep  7 21:46:19 2011
@@ -0,0 +1,28 @@
+package org.apache.tapestry5.integration.app1.pages;
+
+
+import org.apache.tapestry5.alerts.AlertManager;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.beaneditor.Validate;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
+/**
+ * Tests that the canceled event works correctly.
+ */
+public class CanceledEventDemo
+{
+    @Inject
+    private AlertManager alertManager;
+
+    @Property
+    @Validate("required")
+    private String requiredText;
+
+    Object onCanceledFromForm()
+    {
+        alertManager.info("Form was canceled.");
+
+        return this;
+    }
+
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=1166423&r1=1166422&r2=1166423&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java Wed Sep  7 21:46:19 2011
@@ -114,6 +114,8 @@ public class Index
 
                     new Item("CancelDemo", "Cancel Demo", "Use of the cancel option with Submit"),
 
+                    new Item("CanceledEventDemo", "Canceled Event Demo", "Triggering of the canceled event from a form."),
+
                     new Item("PageResetDemo", "PageReset Annotation Demo",
                             "Use of PageReset annotation to re-initialize page state"),