Author: hlship
Date: Mon Nov  3 15:08:40 2008
New Revision: 710212

URL: http://svn.apache.org/viewvc?rev=710212&view=rev
Log:
TAP5-22: Better client side reporting of problems with Zones and triggers is 
needed

Modified:
    tapestry/tapestry5/trunk/src/site/apt/upgrade.apt
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js

Modified: tapestry/tapestry5/trunk/src/site/apt/upgrade.apt
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/upgrade.apt?rev=710212&r1=710211&r2=710212&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/apt/upgrade.apt (original)
+++ tapestry/tapestry5/trunk/src/site/apt/upgrade.apt Mon Nov  3 15:08:40 2008
@@ -12,6 +12,10 @@
   You should also check the {{{release-notes.html}project-wide release notes}} 
for information
   about bugs fixes and other improvements.
 
+Release 5.0.16
+
+  The client-side class Tapestry.Zone has been renamed to Tapestry.ZoneManager.
+
 Release 5.0.15
 
   Method <<<getElementName()>>> of the

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java?rev=710212&r1=710211&r2=710212&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
 Mon Nov  3 15:08:40 2008
@@ -29,15 +29,23 @@
  * Zone renders out as a &lt;div&gt; element and may have content initially, 
or may only get its content as a result of
  * client side activity.
  * <p/>
- * Often, Zone's are initially invisible, in which case the visible parameter 
may be set to false (it defaults to
- * false).
+ * 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 [EMAIL PROTECTED] 
org.apache.tapestry5.corelib.components.ActionLink} whose zone parameter is 
set, the
  * corresponding client-side Tapestry.Zone object is located. It will update 
the content of the Zone's &lt;div&gt; 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.
+ * and update parameters are the <em>names</em> of functions attached to the 
Tapestry.ElementEffect object.    Likewise,
+ * a [EMAIL PROTECTED] org.apache.tapestry5.corelib.components.Form} component 
may also trigger an update of a client-side Zone.
  * <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 are responsible for ensuring that there will not be an id conflict even 
in the face of multiple partial renders
+ * of the page). Failure to provide an explicit id results in a new, and 
non-predictable, id being generated for each
+ * partial render, which will often result in client-side failures to locate 
the element to update when the Zone is
+ * triggered.
  */
 @SupportsInformalParameters
 public class Zone implements ClientElement

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css?rev=710212&r1=710211&r2=710212&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
 Mon Nov  3 15:08:40 2008
@@ -446,7 +446,7 @@
     font-size: large;
     cursor: pointer;
     width: 100%;
-    text-align: center;
+    text-align: left;
     position: fixed;
     z-index: 0;
     left: 0px;

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=710212&r1=710211&r2=710212&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
 Mon Nov  3 15:08:40 2008
@@ -242,12 +242,16 @@
      * we want to present the message clearly to the user).
      * @param className of the new entry to the console, typically "t-err"
      * @param message to display in the console
+     * @param substitutions optional substitutions to interpolate into mesasge
      */
-    updateAjaxConsole : function (className, message)
+    updateAjaxConsole : function (className, message, substitutions)
     {
         if (Tapestry.ajaxConsole == undefined)
             Tapestry.ajaxConsole = Tapestry.createConsole("t-ajax-console");
 
+        if (substitutions != undefined)
+            message = message.interpolate(substitutions);
+
         Tapestry.writeToConsole(Tapestry.ajaxConsole, className, message);
     },
 
@@ -302,12 +306,23 @@
     {
         var message = response.getHeader("X-Tapestry-ErrorMessage");
 
-        Tapestry.updateAjaxConsole("t-err", "Communication with the server 
failed: " + message);
+        Tapestry.ajaxError("Communication with the server failed: " + message);
 
         Tapestry.debug("Ajax failure: Status #{status} for #{request.url}: " + 
message, response);
     },
 
     /**
+     * Writes a message to the Ajax console.
+     *
+     * @param message error message to display
+     * @param substitutions optional substitutions to interpolate into message
+     */
+    ajaxError : function(message, substitutions)
+    {
+        Tapestry.updateAjaxConsole("t-err", message, substitutions);
+    },
+
+    /**
      * Processes a typical Ajax request for a URL invoking the provided 
handler on success.
      * On failure, error() is invoked to inform the user.
      *
@@ -322,7 +337,7 @@
             {
                 if (! response.request.success())
                 {
-                    Tapestry.updateAjaxConsole("t-err", "Server request was 
unsuccesful. There may be a problem accessing the server.");
+                    Tapestry.ajaxError("Server request was unsuccesful. There 
may be a problem accessing the server.");
                     return;
                 }
 
@@ -333,13 +348,43 @@
                 }
                 catch (e)
                 {
-                    Tapestry.updateAjaxConsole("t-err", "Client exception 
processing response: " + e);
+                    Tapestry.ajaxError("Client exception processing response: 
" + e);
                 }
             },
             onException: Tapestry.ajaxFailureHandler,
             onFailure: Tapestry.ajaxFailureHandler })
     },
 
+    /** 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
+     * @return Tapestry.ZoneManager instance for updated zone, or null if not 
found.
+     */
+    findZoneManager : function(element)
+    {
+        var zoneId = $T(element).zoneId;
+        var zoneElement = $(zoneId);
+
+        if (!zoneElement)
+        {
+            Tapestry.ajaxError("Unable to locate Ajax Zone '#{id}' for dynamic 
update.", { id:zoneId});
+            return null;
+        }
+
+        var manager = $T(zoneElement).zoneManager;
+
+        if (!manager)
+        {
+            Tapestry.ajaxError("Ajax Zone '#{id}' does not have an associated 
Tapestry.ZoneManager object.", { id :zoneId });
+            return null;
+        }
+
+        return manager;
+    },
+
+
     /**
      * Used to reconstruct a complete URL from a path that is (or may be) 
relative to window.location.
      * This is used when determining if a JavaScript library or CSS stylesheet 
has already been loaded.
@@ -663,19 +708,21 @@
     },
 
 
+
     /**
      * Convert a form or link into a trigger of an Ajax update that
      * updates the indicated Zone.
+     * @param element id or instance of <form> or <a> element
+     * @param zoneId id of the element to update when link clicked or form 
submitted
      */
-    linkZone : function(element, zoneDiv)
+    linkZone : function(element, zoneId)
     {
         element = $(element);
 
         // Update the element with the id of zone div. This may be changed 
dynamically on the client
         // side.
 
-        $T(element).zone = zoneDiv;
-
+        $T(element).zoneId = zoneId;
 
         if (element.tagName == "FORM")
         {
@@ -689,12 +736,13 @@
 
             element.observe(Tapestry.FORM_PROCESS_SUBMIT_EVENT, function()
             {
+                var zoneManager = Tapestry.findZoneManager(element);
+
+                if (!zoneManager) return;
+
                 var successHandler = function(transport)
                 {
-                    var zoneId = $T(element).zone;
-                    var zoneObject = $T(zoneId).zone;
-
-                    zoneObject.processReply(transport.responseJSON);
+                    zoneManager.processReply(transport.responseJSON);
                 };
 
                 element.sendAjaxRequest({ onSuccess : successHandler });
@@ -707,18 +755,13 @@
 
         element.observe("click", function(event)
         {
-            // Find the zone id for the element, and from there, the 
Tapestry.Zone object
-            // responsible for the zone.  This is evaluated late so that zone 
can be dynamically
-            // changed on the client.  Sorry about the confusion; there's the 
zone <div>, and
-            // there's the Tapestry.Zone object.    Perhaps should rename 
Tapestry.Zone
-            // to Tapestry.ZoneManager?
+            Event.stop(event);
 
-            var zoneId = $T(element).zone;
-            var zoneObject = $T(zoneId).zone;
+            var zoneObject = Tapestry.findZoneManager(element);
 
-            zoneObject.updateFromURL(element.href);
+            if (!zoneObject) return;
 
-            Event.stop(event);
+            zoneObject.updateFromURL(element.href);
         });
     },
 
@@ -758,7 +801,7 @@
 
     zone : function(spec)
     {
-        new Tapestry.Zone(spec);
+        new Tapestry.ZoneManager(spec);
     },
 
     formFragment : function(spec)
@@ -1261,7 +1304,12 @@
 };
 
 
-Tapestry.Zone = Class.create({
+/**
+ * Manages a &lt;div&lt; (or other element) for dynamic updates.
+ *
+ * @param element
+ */
+Tapestry.ZoneManager = Class.create({
     // spec are the parameters for the Zone:
     // trigger: required -- name or instance of link.
     // element: required -- name or instance of div element to be shown, 
hidden and updated
@@ -1278,11 +1326,11 @@
 
         // Link the div back to this zone.
 
-        $T(this.element).zone = this;
+        $T(this.element).zoneManager = this;
 
-        // Look inside the Zone element for an element with the CSS class 
"t-zone-update".
-        // If present, then this is the elements whose content will be 
changed, rather
-        // then the entire Zone div.  This allows a Zone div to contain 
"wrapper" markup
+        // Look inside the managed element for another element with the CSS 
class "t-zone-update".
+        // If present, then this is the element whose content will be changed, 
rather
+        // then the entire zone's element.  This allows a Zone element to 
contain "wrapper" markup
         // (borders and such).  Typically, such a Zone element will initially 
be invisible.
         // The show and update functions apply to the Zone element, not the 
update element.
 
@@ -1304,7 +1352,7 @@
     },
 
     /**
-     * Invoked with a reply (i.e., transport.responseJSON), this updates the 
zone's div
+     * Invoked with a reply (i.e., transport.responseJSON), this updates the 
managed element
      * and processes any JavaScript in the reply.  The response should have a
      * content key, and may have  script, scripts and stylesheets keys.
      * @param reply response in JSON format appropriate to a Tapestry.Zone
@@ -1624,10 +1672,10 @@
  * is used to store additional values related to the element; it is simply an 
annoymous object stored as property
  * <code>_tapestry</code> of the element, created the first time it is 
accessed.
  * <p>This mechanism acts as a namespace, and so helps prevent name
- * conflicts that would occur if properties were stored directly on DOM 
elements, and makes debugging a bit easier (the Tapestry-specific
- * properties are all in one place!).
- * For the moment,
- * added methods stored directly on the object, and are not prefixed in any 
way, valuing readability over preventing naming conflicts.
+ * conflicts that would occur if properties were stored directly on DOM 
elements, and makes debugging a bit easier
+ * (the Tapestry-specific properties are all in one place!).
+ * For the moment, added methods are stored directly on the object, and are 
not prefixed in any way, valuing
+ * readability over preventing naming conflicts.
  *
  * @param element an element instance or element id
  * @return object Tapestry object for the element


Reply via email to