You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/10/19 02:53:36 UTC
[1/8] git commit: Remove Tapestry.ZoneManager - update core/zone
module to take on its responsibilities - modify ProgressiveDisplay to make
use of the core/zone:deferredZoneUpdate
Updated Branches:
refs/heads/5.4-js-rewrite e3939a902 -> 20baae9d1
Remove Tapestry.ZoneManager
- update core/zone module to take on its responsibilities
- modify ProgressiveDisplay to make use of the core/zone:deferredZoneUpdate
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/20baae9d
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/20baae9d
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/20baae9d
Branch: refs/heads/5.4-js-rewrite
Commit: 20baae9d13512a3d0f2cbefa63e94975dcf14e8c
Parents: 764a649
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Oct 18 17:43:41 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Oct 18 17:43:41 2012 -0700
----------------------------------------------------------------------
.../META-INF/modules/core/events.coffee | 11 +-
.../coffeescript/META-INF/modules/core/zone.coffee | 49 +++++-
.../corelib/components/ProgressiveDisplay.java | 36 ++--
.../apache/tapestry5/corelib/components/Zone.java | 48 ++----
.../compatibility/DeprecationWarningImpl.java | 13 ++-
.../services/compatibility/DeprecationWarning.java | 9 +-
.../corelib/components/ProgressiveDisplay.js | 20 ---
.../resources/org/apache/tapestry5/tapestry.js | 125 ---------------
8 files changed, 98 insertions(+), 213 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
index c17b1c0..e920006 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
@@ -69,7 +69,6 @@ define
# field's id. The field will be assigned an id if necesary.
# * Normally, the block is inserted after the field
# * If the field's container has class "input-append" or "input-prepend", then the block is inserted after the container
- #
showValidationError: "t5:field:show-validation-error"
# Defines a number of event names specific to Tapestry Zones. Zones are Tapestry components that are structured
@@ -90,6 +89,14 @@ define
# is made visible after its content is changed, and before this event is triggered.
didUpdate: "t5:zone:did-update"
+ # Triggered on a zone element, the default handler will peform an Ajax request and, when the response is available,
+ # update the zone (via `events.zone.update`). The request should provide a partial page render response. If the
+ # response includes a `content` key, its value will be the markup to replace the zone element's body.
+ #
+ # * memo.url - URL to use for the Ajax request
+ # * memo.parameters - (optional) additional query parameters for the request
+ refresh: "t5:zone:refresh"
+
# Event names for arbitrary elements. These notifications exist primarily to allow for customizations in how
# certain behaviors are presented, for example, to add animation when certain elements are hidden or revealed.
element:
@@ -104,7 +111,7 @@ define
# boolean. The fragment will show or hide itself if necessary (triggering the `element.didShow` or
# `element.didHide` event).
changeVisibility: "t5:fragment:change-visibility"
- # Request that the fragment remove itself entirely. This event is of no practical use, as it is simply equivalent
+ # Requests that the fragment remove itself entirely. This event is of no practical use, as it is simply equivalent
# to invoking `spi/ElementWrapper.remove()` on the fragment's element; the event exists for compatibility with
# Tapestry 5.3 and will be removed in Tapestry 5.5.
remove: "t5:fragment:remove"
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/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 5be2983..737cb8d 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
@@ -14,10 +14,14 @@
# ##core/zone
#
-# Provides a default handler for the `events.zone.update` event, attached to the
-# document body.
-define ["core/spi", "core/events", "_"],
- (spi, events, _) ->
+# Provides a default handler for events related to zones. A zone is any kind of
+# client-side element that can be updated; a zone will normally have a unique id.
+# Typically, a client-side zone element is rendered by, and corresponds to, a server-side
+# core/Zone component; however, certain other components (such as core/ProgressiveDisplay) may
+# also be treated as zones.
+define ["core/spi", "core/events", "core/ajax", "core/console", "_"],
+
+ (spi, events, ajax, console, _) ->
spi.onDocument events.zone.update, (event) ->
this.trigger events.zone.willUpdate
@@ -29,12 +33,41 @@ define ["core/spi", "core/events", "_"],
# The server may have passed down the empty string for the content; that removes the existing content.
# On the other hand, the server may have not provided a content key; in that case, content is undefined
# which means to leave the existing content alone.
+ #
+ # Note that currently, the willUpdate and didUpdate events are triggered even when the zone is not actually
+ # updated. That may be a bug.
unless content is undefined
this.update content
- this.show() unless this.visible()
-
this.trigger events.zone.didUpdate
- # No meaningful value is returned.
- return
\ No newline at end of file
+ spi.onDocument events.zone.refresh, (event) ->
+
+ # A Zone inside a form will render some additional parameters to coordinate updates with the Form on the server.
+ parameters = this.getAttribute "data-zone-parameters"
+
+ parameters = if parameters is null then null else JSON.parse(parameters)
+
+ ajax event.memo.url,
+ parameters: _.extend { "t:zoneid": this.element.id }, parameters, event.memo.parameters
+ onsuccess: (reply) =>
+ this.trigger events.zone.update, content: reply.responseJSON?.content
+
+ # Locates a zone element by its unique id attribute, and (deferred, to a later event loop cycle),
+ # performs a standard refresh of the zone. This is primarily used by the core/ProgressiveDisplay component.
+ #
+ # * id - client id of the element
+ # * url - URL to use to refresh the element.
+ deferredZoneUpdate = (id, url) ->
+
+ _.defer ->
+ zone = spi id
+
+ if zone is null
+ console.error "Could not locate element '#{id}' to update."
+ return
+
+ zone.trigger events.zone.refresh, { url }
+
+
+ return { deferredZoneUpdate }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java
index e26682a..1642d4b 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java
@@ -15,11 +15,12 @@
package org.apache.tapestry5.corelib.components;
import org.apache.tapestry5.*;
-import org.apache.tapestry5.annotations.*;
-import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.annotations.Environmental;
+import org.apache.tapestry5.annotations.Events;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.SupportsInformalParameters;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-import org.apache.tapestry5.json.JSONObject;
+import org.apache.tapestry5.services.compatibility.DeprecationWarning;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
import java.io.IOException;
@@ -42,7 +43,6 @@ import java.io.IOException;
* @since 5.1.0.1
*/
@SupportsInformalParameters
-@Import(library = "ProgressiveDisplay.js", modules = "core/zone")
@Events(EventConstants.PROGRESSIVE_DISPLAY)
@SuppressWarnings("all")
public class ProgressiveDisplay
@@ -71,39 +71,39 @@ public class ProgressiveDisplay
@Environmental
private TrackableComponentEventCallback eventCallback;
+ @Inject
+ private DeprecationWarning deprecationWarning;
+
/**
* Name of a function on the client-side Tapestry.ElementEffect object that
* is invoked after the elements's body
* content has been updated. If not specified, then the basic "highlight"
* method is used, which performs a classic
* "yellow fade" to indicate to the user that and update has taken place.
+ *
+ * @deprecated Deprecated in 5.4 with no replacement.
*/
@Parameter(defaultPrefix = BindingConstants.LITERAL)
private String update;
+ void pageLoaded() {
+ deprecationWarning.ignoredComponentParameters(resources, "update");
+ }
+
Block beginRender(MarkupWriter writer)
{
String clientId = jsSupport.allocateClientId(resources);
String elementName = resources.getElementName("div");
- Element e = writer.element(elementName, "id", clientId);
-
+ writer.element(elementName, "id", clientId);
resources.renderInformalParameters(writer);
- e.addClassName("t-zone");
-
Link link = resources.createEventLink(EventConstants.ACTION, context);
- JSONObject spec = new JSONObject();
-
- if (InternalUtils.isNonBlank(update))
- spec.put("update", update.toLowerCase());
-
- spec.put("element", clientId);
- spec.put("url", link.toURI());
-
- jsSupport.addInitializerCall("progressiveDisplay", spec);
+ jsSupport.require("core/zone").invoke("deferredZoneUpdate").with(clientId, link.toURI());
+ // Return the placeholder for the full content. That will render instead of the main body
+ // of the component.
return initial;
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
index 82bb405..52a395a 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
@@ -22,6 +22,7 @@ import org.apache.tapestry5.corelib.internal.HiddenFieldPositioner;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.internal.services.RequestConstants;
import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.*;
import org.apache.tapestry5.services.compatibility.DeprecationWarning;
@@ -33,21 +34,13 @@ import org.slf4j.Logger;
* Zone renders out as a <div> element (or whatever is specified in the template) and may have content initially,
* or may only get its content as a result of client side activity.
* <p/>
- * Often, Zones are initially invisible, in which case the visible parameter may be set to false (it defaults to true).
- * <p/>
- * When a user clicks an {@link org.apache.tapestry5.corelib.components.ActionLink} whose zone parameter is set, the
- * corresponding client-side Tapestry.ZoneManager object is located. It will update the content of the Zone's
- * <div> and then invoke either a show method (if the div is not visible) or an update method (if the div is
- * visible). The show and update parameters are the <em>names</em> of functions attached to the Tapestry.ElementEffect
- * object. Likewise, a {@link org.apache.tapestry5.corelib.components.Form} component may also trigger an update of a
- * client-side Zone.
+ * When a user clicks an {@link org.apache.tapestry5.corelib.components.ActionLink} whose zone parameter is set triggers a
+ * series of client-side behaviors, and an Ajax request to the server.
* <p/>
* The server side event handler can return a {@link org.apache.tapestry5.Block} or a component to render as the new
* content on the client side. Often, re-rendering the Zone's {@linkplain #getBody() body} is useful. Multiple
* client-side zones may be updated via the {@link org.apache.tapestry5.services.ajax.AjaxResponseRenderer} service.
* <p/>
- * Renders informal parameters, adding CSS class "t-zone" and possibly, "t-invisible".
- * <p/>
* You will often want to specify the id parameter of the Zone, in addition to it's Tapestry component id; this "locks
* down" the client-side id, so the same value is used even in later partial renders of the page (essential if the Zone
* is nested inside another Zone). When you specify the client-side id, it is used exactly as provided (meaning that you
@@ -152,6 +145,10 @@ public class Zone implements ClientBodyElement
@Inject
private DeprecationWarning deprecationWarning;
+ @Inject
+ @Symbol(SymbolConstants.COMPACT_JSON)
+ private boolean compactJSON;
+
String defaultElementName()
{
return resources.getElementName("div");
@@ -159,46 +156,29 @@ public class Zone implements ClientBodyElement
void pageLoaded()
{
- if (resources.isBound("show"))
- {
- deprecationWarning.ignoredComponentParameter(resources, "show");
- }
-
- if (resources.isBound("update"))
- {
- deprecationWarning.ignoredComponentParameter(resources, "update");
- }
-
- if (resources.isBound("visible"))
- {
- deprecationWarning.ignoredComponentParameter(resources, "visible");
- }
+ deprecationWarning.ignoredComponentParameters(resources, "show", "update", "visible");
}
void beginRender(MarkupWriter writer)
{
clientId = resources.isBound("id") ? idParameter : javascriptSupport.allocateClientId(resources);
- Element e = writer.element(elementName, "id", clientId);
+ Element e = writer.element(elementName,
+ "id", clientId,
+ "data-zone", "true");
resources.renderInformalParameters(writer);
- // This will likely be removed in 5.5.
- e.addClassName("t-zone");
-
- JSONObject spec = new JSONObject("element", clientId);
-
insideForm = formSupport != null;
if (insideForm)
{
JSONObject parameters = new JSONObject(RequestConstants.FORM_CLIENTID_PARAMETER, formSupport.getClientId(),
RequestConstants.FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId());
- spec.put("parameters", parameters);
- }
-
- javascriptSupport.addInitializerCall("zone", spec);
+ e.attribute("data-zone-parameters",
+ parameters.toString(compactJSON));
+ }
if (insideForm)
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/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 14dd142..996f912 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
@@ -132,9 +132,18 @@ public class DeprecationWarningImpl implements DeprecationWarning
}
@Override
- public void ignoredComponentParameter(ComponentResources resources, String parameterName)
+ public void ignoredComponentParameters(ComponentResources resources, String... parameterNames)
{
- componentParameter(resources, parameterName, "This parameter is ignored and may be removed in a future release.");
+ assert resources != null;
+
+ for (String name : parameterNames)
+ {
+
+ if (resources.isBound(name))
+ {
+ componentParameter(resources, name, "This parameter is ignored and may be removed in a future release.");
+ }
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java
index 813716d..29bed6f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/compatibility/DeprecationWarning.java
@@ -40,14 +40,15 @@ public interface DeprecationWarning
void componentParameter(ComponentResources resources, String parameterName, String message);
/**
- * The most common case: a parameter is no longer supported and will likely be removed in the future.
+ * The most common case: checks to see if the parameter name is bound and if so emits a warning that the parameter
+ * is ignored and will be removed.
*
* @param resources
* identifies the component, including its location
- * @param parameterName
- * name of the deprecated parameter
+ * @param parameterNames
+ * names of the deprecated parameters
*/
- void ignoredComponentParameter(ComponentResources resources, String parameterName);
+ void ignoredComponentParameters(ComponentResources resources, String... parameterNames);
/**
* Used to identify a specific parameter value that is no longer supported. The first time this combination of
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ProgressiveDisplay.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ProgressiveDisplay.js b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ProgressiveDisplay.js
deleted file mode 100644
index 9f5df69..0000000
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/ProgressiveDisplay.js
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2009 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.
-
-Tapestry.Initializer.progressiveDisplay = function(spec)
-{
- var mgr = new Tapestry.ZoneManager(spec);
-
- mgr.updateFromURL.bind(mgr).defer(spec.url);
-};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20baae9d/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 bcb1d73..448b633 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
@@ -241,51 +241,6 @@ define("core/compat/tapestry", [
loggingFunction.call(this, message);
},
- /**
- * Obtains the Tapestry.ZoneManager object associated with a triggering
- * element (an <a> or <form>) configured to update a zone.
- * Writes errors to the AjaxConsole if the zone and ZoneManager can not be
- * resolved.
- *
- * @param element
- * triggering element (id or instance)
- * @return Tapestry.ZoneManager instance for updated zone, or null if not
- * found.
- */
- findZoneManager: function (element) {
- var zoneId = $T(element).zoneId;
-
- return Tapestry.findZoneManagerForZone(zoneId);
- },
-
- /**
- * Obtains the Tapestry.ZoneManager object associated with a zone element
- * (usually a <div>). Writes errors to the Ajax console if the element
- * or manager can not be resolved.
- *
- * @param zoneElement
- * zone element (id or instance)
- * @return Tapestry.ZoneManager instance for zone, or null if not found
- */
- findZoneManagerForZone: function (zoneElement) {
- var element = $(zoneElement);
-
- if (!element) {
- Tapestry.error(Tapestry.Messages.missingZone, {
- id: zoneElement
- });
- return null;
- }
-
- var manager = $T(element).zoneManager;
-
- if (!manager) {
- Tapestry.error(Tapestry.Messages.noZoneManager, element);
- return null;
- }
-
- return manager;
- },
/**
* Convert a user-provided localized number to an ordinary number (not a
@@ -872,11 +827,6 @@ define("core/compat/tapestry", [
});
},
- zone: function (spec) {
- new Tapestry.ZoneManager(spec);
- },
-
-
formInjector: function (spec) {
new Tapestry.FormInjector(spec);
},
@@ -1136,81 +1086,6 @@ define("core/compat/tapestry", [
none: _none
};
- /**
- * Manages a <div> (or other element) for dynamic updates.
- *
- */
- Tapestry.ZoneManager = Class.create({
- /*
- * spec are the parameters for the Zone: trigger:
- * spec.element -- id or instance of div element
- * spec.parameters -- additional parameters (related to Zones nested inside Forms) (optional)
- * Prior releases included spec.hide and spec.show (to control animations) but these have been
- * deprecated.
- */
- initialize: function (spec) {
- this.elementId = spec.element;
-
- // When updates arrive, the outer element is always made visible.
- this.element = spi(spec.element);
- this.specParameters = spec.parameters;
-
- /* Link the div back to this zone. */
-
- $T(this.element.element).zoneManager = this;
- },
-
- /**
- * Updates the zone's content; as of 5.4 this is just a shell
- * that triggers the events.zone.update event; see the core/zone module
- * for the default handler for that event.
- *
- * @param content
- */
- show: function (content) {
- this.element.trigger(events.zone.update, { content: content });
- },
-
- /**
- * Invoked with a reply (i.e., transport.responseJSON), this updates the
- * managed element and processes any JavaScript in the reply. The zone's
- * content is only updated if the response has a content key.
- *
- * @param reply
- * response in JSON format appropriate to a Tapestry.Zone
- */
- processReply: function (response) {
- /*
- * In a multi-zone update, the reply.content may be missing, in
- * which case, leave the current content in place. TAP5-1177
- */
- var reply = response.responseJSON;
-
- reply && reply.content != undefined && this.show(reply.content);
- },
-
- /**
- * Initiates an Ajax request to update this zone by sending a request to the
- * URL. Expects the correct JSON reply (wth keys content, etc.).
- *
- * @param URL
- * component event request URL
- * @param parameters
- * object containing additional key/value pairs (optional)
- */
- updateFromURL: function (URL, parameters) {
-
- var fullParameters = _.extend({ "t:zoneid": this.elementId },
- this.specParameters,
- parameters);
-
- ajax(URL, {
- parameters: fullParameters,
- onsuccess: _.bind(this.processReply, this)
- });
- }
- });
-
Tapestry.FormInjector = Class.create({
initialize: function (spec) {