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 2012/08/13 20:47:05 UTC

[5/9] git commit: Remove support for client-validation on blur Deprecate ClientValidation.BLUR, treat it as SUBMIT

Remove support for client-validation on blur
Deprecate ClientValidation.BLUR, treat it as SUBMIT


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/7384c033
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/7384c033
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/7384c033

Branch: refs/heads/5.4-js-rewrite
Commit: 7384c033c5130f7d65c2b9bf42c60c7c1a3c8016
Parents: 749fbf9
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Aug 13 10:43:24 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Aug 13 10:43:24 2012 -0700

----------------------------------------------------------------------
 54_RELEASE_NOTES.txt                               |   12 ++++-
 .../apache/tapestry5/corelib/ClientValidation.java |   14 +++---
 .../apache/tapestry5/corelib/components/Form.java  |   38 ++++++++++-----
 .../compatibility/DeprecationWarningImpl.java      |    4 +-
 .../apache/tapestry5/services/TapestryModule.java  |   13 +-----
 .../resources/org/apache/tapestry5/tapestry.js     |   16 ------
 .../app1/pages/BeanEditRemoveReorder.java          |    4 +-
 7 files changed, 48 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7384c033/54_RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/54_RELEASE_NOTES.txt b/54_RELEASE_NOTES.txt
index f05b7ab..fa71ea1 100644
--- a/54_RELEASE_NOTES.txt
+++ b/54_RELEASE_NOTES.txt
@@ -10,17 +10,25 @@ RequireJS, which may mean that global values exported by the libraries are not v
 properties to the global JavaScript window object, rather than assume that the context (this) is the window.
 
 The interface org.apache.tapestry5.services.assets.ResourceTransformer has had a new method added:
-getTransformedContentType().
+getTransformedContentType(). This makes it possible to determine which file extensions map to which content types
+(for example, A ResourceTransformer for CoffeeScript files, with extension ".coffee", would map to "text/javascript").
 
 Older versions of Tapestry included client-side support for an element with the CSS class "t-zone-update" as the actual
 element to be updated when new content is provided for the zone in a partial page render response. This feature has been
 removed with no replacement.
 
 Minor changes to Tapestry.ElementEffects.  Despite the names of the properties (kept for compatibility), all "effects"
-are now simply make the element appear or hide, with no animation.
+now simply make the element appear or hide, with no animation.
 
 Tapestry code no longer makes use of Scriptaculous. Instead, Tapestry will fire events on elements, and user code may
 decide to animate them using whatever library is desired.
 
 On the client side, the "floating console" is only used in cases where a native console is not available. (Is this a
 change from 5.3?)
+
+Support for validating fields on blur (i.e., when tabbing out of a field) has been removed. Validation now occurs when
+the form is submitted, or not at all. The ClientValidation.BLUR enum value has been deprecated and is now treated as
+SUBMIT.
+
+Prior releases of Tapestry mapped "true" and "false" values for Form.clientValidation to BLUR and NONE. This mapping
+was introduced in Tapestry 5.2, and has now been removed.

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7384c033/tapestry-core/src/main/java/org/apache/tapestry5/corelib/ClientValidation.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/ClientValidation.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/ClientValidation.java
index 54ca74a..f8bab7c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/ClientValidation.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/ClientValidation.java
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -15,22 +15,22 @@
 package org.apache.tapestry5.corelib;
 
 /**
- * Controls if and how client-side form input validation occurs. For compatibility with Tapestry 5.1,
- * a coercion from "true" to {@link #BLUR} and from "false" to {@link #NONE} are added (though these
- * may be removed some time after Tapestry 5.2).
- * 
+ * Controls if and how client-side form input validation occurs.
+ *
  * @since 5.2.2
  */
 public enum ClientValidation
 {
     /**
-     * Fields validate as the user tabs out of them ("onblur" client side event), as well as when the form submits. This
-     * is the default behavior.
+     * Fields validate as the user tabs out of them ("onblur" client side event), as well as when the form submits.
+     *
+     * @deprecated Deprecated in 5.4, and no longer supported.
      */
     BLUR,
 
     /**
      * Fields only validate when the form submits (validation errors will prevent the form from actually submitting).
+     * This is the default behavior.
      */
     SUBMIT,
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7384c033/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
index 59cebd0..3d179dc 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+// Copyright 2006-2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ import org.apache.tapestry5.json.JSONArray;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.runtime.Component;
 import org.apache.tapestry5.services.*;
+import org.apache.tapestry5.services.compatibility.DeprecationWarning;
 import org.apache.tapestry5.services.javascript.InitializationPriority;
 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
 import org.slf4j.Logger;
@@ -80,7 +81,6 @@ import java.io.ObjectInputStream;
  * During submission it also pushes a {@link Heartbeat} into the environment, which is {@link org.apache.tapestry5.services.Heartbeat#end() ended} just before
  * {@linkplain FormSupport#defer(Runnable) deferred FormSupport operations} are executed.
  * </p>
- * </p>
  *
  * @tapestrydoc
  * @see BeanEditForm
@@ -136,10 +136,11 @@ public class Form implements ClientElement, FormValidationControl
     private boolean clientLogicDefaultEnabled;
 
     /**
-     * Controls when client validation occurs on the client, if at all. Defaults to {@link ClientValidation#BLUR}.
+     * Controls when client validation occurs on the client, if at all. Defaults to {@link ClientValidation#SUBMIT}.
+     * {@link ClientValidation#BLUR} was the default, prior to Tapestry 5.4, but is no longer supported.
      */
     @Parameter(allowNull = false, defaultPrefix = BindingConstants.LITERAL)
-    private ClientValidation clientValidation = clientLogicDefaultEnabled ? ClientValidation.BLUR
+    private ClientValidation clientValidation = clientLogicDefaultEnabled ? ClientValidation.SUBMIT
             : ClientValidation.NONE;
 
     /**
@@ -251,6 +252,9 @@ public class Form implements ClientElement, FormValidationControl
     @Inject
     private PropertyAccess propertyAccess;
 
+    @Inject
+    private DeprecationWarning deprecationWarning;
+
     private String clientId;
 
     @Inject
@@ -296,7 +300,14 @@ public class Form implements ClientElement, FormValidationControl
         FormSupport existing = environment.peek(FormSupport.class);
 
         if (existing != null)
+        {
             throw new TapestryException(messages.get("core-form-nesting-not-allowed"), existing, null);
+        }
+
+        if (clientValidation == ClientValidation.BLUR)
+        {
+            deprecationWarning.componentParameterValue(resources, "clientValidation", clientValidation, "BLUR is no longer supported, starting in 5.4. Validation will occur as with SUBMIT.");
+        }
     }
 
     void beginRender(MarkupWriter writer)
@@ -373,8 +384,8 @@ public class Form implements ClientElement, FormValidationControl
 
     private void addJavaScriptInitialization()
     {
-        JSONObject validateSpec = new JSONObject().put("blur", clientValidation == ClientValidation.BLUR).put("submit",
-                clientValidation != ClientValidation.NONE);
+        JSONObject validateSpec = new JSONObject()
+                .put("submit", clientValidation != ClientValidation.NONE);
 
         JSONObject spec = new JSONObject("formId", clientId).put("validate", validateSpec);
 
@@ -394,12 +405,15 @@ public class Form implements ClientElement, FormValidationControl
      * <p/>
      * This method may also be invoked as the handler for the "internalCreateRenderTimeFormSupport" event.
      *
-     * @param clientId   the client-side id for the rendered form
-     *                   element
-     * @param actionSink used to collect component actions that will, ultimately, be
-     *                   written as the t:formdata hidden
-     *                   field
-     * @param allocator  used to allocate unique ids
+     * @param clientId
+     *         the client-side id for the rendered form
+     *         element
+     * @param actionSink
+     *         used to collect component actions that will, ultimately, be
+     *         written as the t:formdata hidden
+     *         field
+     * @param allocator
+     *         used to allocate unique ids
      * @return form support object
      */
     @OnEvent("internalCreateRenderTimeFormSupport")

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7384c033/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java
index aeb6b22..88a84fc 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/compatibility/DeprecationWarningImpl.java
@@ -91,11 +91,11 @@ public class DeprecationWarningImpl implements DeprecationWarning
 
         deprecations.put(key, true);
 
-        logger.error(String.format("Component %s, parameter %s. %s\n(at %s)",
+        logger.error(String.format("Component %s, parameter %s: %s\n(at %s)",
                 key.completeId,
                 parameterName,
                 message,
-                resources.getLocation());
+                resources.getLocation()));
     }
 
     public void setupClearDeprecationsWhenInvalidated(

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7384c033/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
index 16bef0f..1e4d616 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
+// Copyright 2006-2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import org.apache.tapestry5.annotations.*;
 import org.apache.tapestry5.annotations.ContentType;
 import org.apache.tapestry5.beaneditor.DataTypeConstants;
 import org.apache.tapestry5.beaneditor.Validate;
-import org.apache.tapestry5.corelib.ClientValidation;
 import org.apache.tapestry5.grid.GridConstants;
 import org.apache.tapestry5.grid.GridDataSource;
 import org.apache.tapestry5.internal.*;
@@ -96,7 +95,6 @@ import org.apache.tapestry5.services.security.WhitelistAnalyzer;
 import org.apache.tapestry5.services.templates.ComponentTemplateLocator;
 import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
 import org.apache.tapestry5.services.transform.InjectionProvider2;
-import org.apache.tapestry5.util.StringToEnumCoercion;
 import org.apache.tapestry5.validator.*;
 import org.slf4j.Logger;
 
@@ -1160,15 +1158,6 @@ public final class TapestryModule
             }
         }));
 
-        // Add support for "true" and "false", for compatibility with Tapestry 5.1 and earlier.
-        // These aliases may be removed in some later release.
-
-        StringToEnumCoercion<ClientValidation> stringToClientValidationCoercion = StringToEnumCoercion
-                .create(ClientValidation.class).addAlias("true", ClientValidation.BLUR)
-                .addAlias("false", ClientValidation.NONE);
-
-        configuration.add(CoercionTuple.create(String.class, ClientValidation.class, stringToClientValidationCoercion));
-
         configuration.add(CoercionTuple.create(ValueEncoder.class, ValueEncoderFactory.class, new Coercion<ValueEncoder, ValueEncoderFactory>()
         {
             public ValueEncoderFactory coerce(ValueEncoder input)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7384c033/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
index fb4488b..af0a91a 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
@@ -1339,7 +1339,6 @@ define("core/compat/tapestry", [
 
         initialize: function (spec) {
             this.form = $(spec.formId);
-            this.validateOnBlur = spec.validate.blur;
             this.validateOnSubmit = spec.validate.submit;
 
             this.form.onsubmit = this.handleSubmit.bindAsEventListener(this);
@@ -1464,21 +1463,6 @@ define("core/compat/tapestry", [
 
             var fem = $(this.field.form).getFormEventManager();
 
-            if (fem.validateOnBlur) {
-
-                document.observe(Tapestry.FOCUS_CHANGE_EVENT, function (event) {
-                    /*
-                     * If changing focus *within the same form* then perform
-                     * validation. Note that Tapestry.currentFocusField does not
-                     * change until after the FOCUS_CHANGE_EVENT notification.
-                     */
-                    if (Tapestry.currentFocusField == this.field
-                            && this.field.form == event.memo.form)
-                        this.validateInput();
-
-                }.bindAsEventListener(this));
-            }
-
             if (fem.validateOnSubmit) {
                 $(this.field.form).observe(Tapestry.FORM_VALIDATE_FIELDS_EVENT,
                         this.validateInput.bindAsEventListener(this));

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7384c033/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditRemoveReorder.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditRemoveReorder.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditRemoveReorder.java
index b57a8f8..b2c050a 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditRemoveReorder.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditRemoveReorder.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2010 The Apache Software Foundation
+// Copyright 2007, 2010, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ public class BeanEditRemoveReorder extends BeanEditorDemo
     @Override
     public ClientValidation getClientValidation()
     {
-        return ClientValidation.BLUR;
+        return ClientValidation.SUBMIT;
     }
 
     @Override