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/10/20 03:16:53 UTC

[1/2] git commit: Replace T5.initializers.linkZone with a document event handler inside core/zone, triggered by the data-update-zone attribute

Updated Branches:
  refs/heads/5.4-js-rewrite d93feaaa8 -> 57d12212d


Replace T5.initializers.linkZone with a document event handler inside core/zone, triggered by the data-update-zone attribute


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

Branch: refs/heads/5.4-js-rewrite
Commit: 57d12212d264e68b43e07def4e7c707a1eaea2d4
Parents: 1ba8c13
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Oct 19 18:10:25 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Oct 19 18:10:25 2012 -0700

----------------------------------------------------------------------
 54_RELEASE_NOTES.txt                               |    4 +
 .../coffeescript/META-INF/modules/core/zone.coffee |   28 +++
 .../corelib/base/AbstractComponentEventLink.java   |   15 +-
 .../services/ClientBehaviorSupportImpl.java        |    3 -
 .../tapestry5/services/ClientBehaviorSupport.java  |    6 +-
 .../resources/org/apache/tapestry5/tapestry.js     |   16 --
 .../services/ClientBehaviorSupportImplTest.java    |  143 ---------------
 7 files changed, 41 insertions(+), 174 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/57d12212/54_RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/54_RELEASE_NOTES.txt b/54_RELEASE_NOTES.txt
index 4721985..d6a4ffe 100644
--- a/54_RELEASE_NOTES.txt
+++ b/54_RELEASE_NOTES.txt
@@ -124,3 +124,7 @@ The property edit blocks contributed to the BeanBlockSource service should expec
 div.control-group, which is provided around the editor for each property.
 
 
+== ClientBehaviorSupport
+
+This service, primarily used by built-in components in Tapestry 5.3, is no longer useful in 5.4. The service
+still exists, but the methods do nothing, and the service and interface will be removed in 5.5.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/57d12212/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
index ca6c0d6..4c4dadc 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
@@ -22,6 +22,34 @@
 define ["core/spi", "core/events", "core/ajax", "core/console", "_"],
 
   (spi, events, ajax, console, _) ->
+
+    findZone = (element) ->
+      zoneId = element.getAttribute "data-update-zone"
+
+      if zoneId is "^"
+        zone = element.findContainer "[data-zone]"
+
+        if zone is null
+          console.error "Unable to locate containing zone for #{element}."
+
+        return zone
+
+      zone = spi zoneId
+
+      if zone is null
+        console.error "Unable to locate zone '#{zoneId}'."
+
+      return zone
+
+    spi.onDocument "click", "a[data-update-zone]", ->
+
+      zone = findZone this
+
+      if zone
+        zone.trigger events.zone.refresh,  url: this.getAttribute "href"
+
+      return false
+
     spi.onDocument events.zone.update, (event) ->
 
       this.trigger events.zone.willUpdate

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/57d12212/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractComponentEventLink.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractComponentEventLink.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractComponentEventLink.java
index 97fcd34..498eddd 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractComponentEventLink.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractComponentEventLink.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009, 2011 The Apache Software Foundation
+// Copyright 2008, 2009, 2011, 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.
@@ -17,10 +17,8 @@ package org.apache.tapestry5.corelib.base;
 import org.apache.tapestry5.BindingConstants;
 import org.apache.tapestry5.Link;
 import org.apache.tapestry5.MarkupWriter;
-import org.apache.tapestry5.annotations.Environmental;
 import org.apache.tapestry5.annotations.Parameter;
 import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.services.ClientBehaviorSupport;
 import org.apache.tapestry5.services.Request;
 
 /**
@@ -43,9 +41,6 @@ public abstract class AbstractComponentEventLink extends AbstractLink
     @Parameter(defaultPrefix = BindingConstants.LITERAL)
     private String zone;
 
-    @Environmental
-    private ClientBehaviorSupport clientBehaviorSupport;
-
     @Inject
     private Request request;
 
@@ -57,16 +52,14 @@ public abstract class AbstractComponentEventLink extends AbstractLink
 
         writeLink(writer, link);
 
-        if (zone != null)
-        {
-            clientBehaviorSupport.linkZone(getClientId(), zone, link);
-        }
+        writer.attributes("data-update-zone", zone);
     }
 
     /**
      * Invoked to create the Link that will become the href attribute of the output.
      *
-     * @param eventContext the context as an object array, possibly null
+     * @param eventContext
+     *         the context as an object array, possibly null
      */
     protected abstract Link createLink(Object[] eventContext);
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/57d12212/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java
index 7f0cd8e..2e50595 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java
@@ -65,9 +65,6 @@ public class ClientBehaviorSupportImpl implements ClientBehaviorSupport
 
     public void linkZone(String linkId, String elementId, Link eventLink)
     {
-        JSONObject spec = new JSONObject("linkId", linkId, "zoneId", elementId, "url", eventLink.toURI());
-
-        javascriptSupport.addInitializerCall("linkZone", spec);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/57d12212/tapestry-core/src/main/java/org/apache/tapestry5/services/ClientBehaviorSupport.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/ClientBehaviorSupport.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/ClientBehaviorSupport.java
index 2ca64ab..cb8e7cb 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/ClientBehaviorSupport.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/ClientBehaviorSupport.java
@@ -22,6 +22,8 @@ import org.apache.tapestry5.corelib.data.InsertPosition;
  * Collects details about zone usage for efficient initialization of the client side objects. This has grown to include
  * the client-side behavior associated with {@link org.apache.tapestry5.corelib.components.FormFragment}s.
  *
+ * This interface is only kept for binary compatibility in Tapestry 5.4; the implementation no longer does anything.
+ *
  * @see org.apache.tapestry5.corelib.components.Zone
  * @deprecated Deprecated in 5.4 with no replacement. Use {@link org.apache.tapestry5.services.javascript.JavaScriptSupport} directly,
  *             instead.
@@ -40,12 +42,14 @@ public interface ClientBehaviorSupport
      *         default
      * @param updateFunctionName
      *         name of function used to highlight the function after an update, or null for default
-     * @deprecated In 5.4 with no replacement
      */
     void addZone(String clientId, String showFunctionName, String updateFunctionName);
 
     /**
      * Sets the client-side onclick handler for an &lt;a&gt; element to perform an Ajax update of a zone.
+     * <p/>
+     * Starting in Tapestry 5.4, this can be accomplished by adding a "data-update-zone" attribute
+     * to the element.  The attribute value may be {@code ^} or the id of the zone's client element.
      *
      * @param linkId
      *         id of the link to Ajax enable

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/57d12212/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 448b633..8aa80f2 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
@@ -615,22 +615,6 @@ define("core/compat/tapestry", [
             });
         },
 
-        /**
-         * Convert a form or link into a trigger of an Ajax update that
-         * updates the indicated Zone.
-         *
-         * @param spec.linkId
-         *            id or instance of &lt;form&gt; or &lt;a&gt; element
-         * @param spec.zoneId
-         *            id of the element to update when link clicked or form
-         *            submitted
-         * @param spec.url
-         *            absolute component event request URL
-         */
-        linkZone: function (spec) {
-            Tapestry.Initializer.updateZoneOnEvent("click", spec.linkId,
-                    spec.zoneId, spec.url);
-        },
 
         /**
          * Converts a link into an Ajax update of a Zone. The url includes

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/57d12212/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java
deleted file mode 100644
index 0df21d6..0000000
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2007, 2008, 2010 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.
-// 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 org.apache.tapestry5.internal.services;
-
-import org.apache.tapestry5.Link;
-import org.apache.tapestry5.json.JSONObject;
-import org.apache.tapestry5.services.Environment;
-import org.apache.tapestry5.services.FormSupport;
-import org.apache.tapestry5.services.javascript.JavaScriptSupport;
-import org.apache.tapestry5.test.TapestryTestCase;
-import org.testng.annotations.Test;
-
-public class ClientBehaviorSupportImplTest extends TapestryTestCase
-{
-    @Test
-    public void no_changes()
-    {
-        ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(null, null);
-
-        setup.commit();
-    }
-
-    @Test
-    public void add_links()
-    {
-        Link link1 = mockLink("/link1");
-        JavaScriptSupport js = mockJavaScriptSupport();
-
-        js.addInitializerCall("linkZone", new JSONObject("linkId", "client1", "zoneId", "zone1", "url", "/link1"));
-
-        replay();
-
-        ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, null);
-
-        setup.linkZone("client1", "zone1", link1);
-
-        setup.commit();
-
-        verify();
-    }
-
-    @Test
-    public void add_zones()
-    {
-        JavaScriptSupport js = mockJavaScriptSupport();
-        Environment environment = mockEnvironment();
-
-        expect(environment.peek(FormSupport.class)).andReturn(null).atLeastOnce();
-
-        js.addInitializerCall("zone", new JSONObject("element", "client1"));
-        js.addInitializerCall("zone", new JSONObject("element", "client2"));
-
-        replay();
-
-        ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
-
-        setup.addZone("client1", null, null);
-        setup.addZone("client2", null, null);
-
-        verify();
-    }
-
-    @Test
-    public void add_zone_inside_form()
-    {
-        JavaScriptSupport js = mockJavaScriptSupport();
-        Environment environment = mockEnvironment();
-        FormSupport fs = mockFormSupport();
-
-        expect(environment.peek(FormSupport.class)).andReturn(fs).atLeastOnce();
-
-        expect(fs.getClientId()).andReturn("myform");
-        expect(fs.getFormComponentId()).andReturn("MyPage.myform");
-
-        JSONObject expected = new JSONObject(String.format(
-                "{element:'client1', parameters:{'%s': 'myform', '%s': 'MyPage.myform' }}",
-                RequestConstants.FORM_CLIENTID_PARAMETER, RequestConstants.FORM_COMPONENTID_PARAMETER));
-
-        js.addInitializerCall("zone", expected);
-
-        replay();
-
-        ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
-
-        setup.addZone("client1", null, null);
-
-        verify();
-    }
-
-    @Test
-    public void zones_with_functions()
-    {
-        JavaScriptSupport js = mockJavaScriptSupport();
-        Environment environment = mockEnvironment();
-
-        expect(environment.peek(FormSupport.class)).andReturn(null).atLeastOnce();
-
-        js.addInitializerCall("zone", new JSONObject("{'element':'client1', 'show':'showme' }"));
-        js.addInitializerCall("zone", new JSONObject("{'element':'client2', 'update':'updateme' }"));
-
-        replay();
-
-        ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
-
-        setup.addZone("client1", "showme", null);
-        setup.addZone("client2", null, "updateme");
-
-        verify();
-    }
-
-    @Test
-    public void zone_function_names_are_converted_to_lower_case()
-    {
-        JavaScriptSupport js = mockJavaScriptSupport();
-        Environment environment = mockEnvironment();
-
-        expect(environment.peek(FormSupport.class)).andReturn(null).atLeastOnce();
-
-        js.addInitializerCall("zone", new JSONObject("{'element':'client1', 'show':'showme' }"));
-        js.addInitializerCall("zone", new JSONObject("{'element':'client2', 'update':'updateme' }"));
-
-        replay();
-
-        ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
-
-        setup.addZone("client1", "ShowMe", null);
-        setup.addZone("client2", null, "UpdateMe");
-
-        verify();
-    }
-}