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 2009/02/27 20:04:39 UTC

svn commit: r748645 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/ main/java/org/apache/tapestry5/corelib/components/ main/resources/org/apache/tapestry5/ test/app1/ test/java/org/apache/tapestry5/integration/app1/pages/

Author: hlship
Date: Fri Feb 27 19:04:37 2009
New Revision: 748645

URL: http://svn.apache.org/viewvc?rev=748645&view=rev
Log:
TAP5-483: ProgressiveDisplay component should suport a context parameter and fire an event to inform the container what data is to be displayed

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ProgressiveDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ProgressiveDemo.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java?rev=748645&r1=748644&r2=748645&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/EventConstants.java Fri Feb 27 19:04:37 2009
@@ -132,4 +132,13 @@
      * @since 5.1.0.0
      */
     public static final String SYNCHRONIZE_VALUES = "synchronizeValues";
+
+    /**
+     * Event triggered by {@link org.apache.tapestry5.corelib.components.ProgressiveDisplay} component to inform its
+     * container of what context (if any) is available. The event handler may return a renderable object or null. If
+     * null is returned, the component renders its own body as the partial markup response.
+     *
+     * @since 5.1.0.1
+     */
+    public static final String PROGRESSIVE_DISPLAY = "progressiveDisplay";
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java?rev=748645&r1=748644&r2=748645&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/ProgressiveDisplay.java Fri Feb 27 19:04:37 2009
@@ -20,9 +20,13 @@
 import org.apache.tapestry5.annotations.Parameter;
 import org.apache.tapestry5.annotations.SupportsInformalParameters;
 import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.internal.services.ComponentResultProcessorWrapper;
 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.ComponentEventResultProcessor;
+
+import java.io.IOException;
 
 /**
  * A component used to implement the <a href="http://en.wikipedia.org/wiki/Progressive_enhancement">progressive
@@ -30,8 +34,10 @@
  * ...") and an Ajax request then supplies the component's true body. This results in much faster page loads. You can
  * even nest these!
  * <p/>
- * The component simply does not render its body on initial render, but then supplies its body as the partial render
- * content in the Ajax request.
+ * The component simply does not render its body on initial render. On the subsequent action event request, it fires a
+ * {@link org.apache.tapestry5.EventConstants#PROGRESSIVE_DISPLAY} event to inform the container about the (optional)
+ * event context. The event handler method may return a renderable object; if not then the component's body is rendered
+ * as the partial markup response.
  *
  * @since 5.1.0.1
  */
@@ -46,12 +52,22 @@
     @Parameter(defaultPrefix = BindingConstants.LITERAL, value = "block:defaultInitial")
     private Block initial;
 
+    /**
+     * If provided, this is the event context, which will be provided via the {@link
+     * org.apache.tapestry5.EventConstants#PROGRESSIVE_DISPLAY event}.
+     */
+    @Parameter
+    private Object[] context;
+
     @Inject
     private ComponentResources resources;
 
     @Environmental
     private RenderSupport renderSupport;
 
+    @Environmental
+    private ComponentEventResultProcessor resultProcessor;
+
     /**
      * 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
@@ -71,7 +87,7 @@
 
         e.addClassName("t-zone");
 
-        Link link = resources.createEventLink(EventConstants.ACTION);
+        Link link = resources.createEventLink(EventConstants.ACTION, context);
 
         JSONObject spec = new JSONObject();
 
@@ -86,8 +102,15 @@
         return initial;
     }
 
-    Block onAction()
+    Object onAction(EventContext context) throws IOException
     {
+        ComponentResultProcessorWrapper wrapper = new ComponentResultProcessorWrapper(resultProcessor);
+
+        resources.triggerContextEvent(EventConstants.PROGRESSIVE_DISPLAY, context, wrapper);
+
+        if (wrapper.isAborted())
+            return null;
+
         return resources.getBody();
     }
 

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=748645&r1=748644&r2=748645&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 Fri Feb 27 19:04:37 2009
@@ -328,6 +328,15 @@
         return new Ajax.Request(url, {
             onSuccess: function(response, jsonResponse)
             {
+                // When the page is unloaded, pending Ajax requests appear to terminate
+                // as succesful (but with no reply value). Since we're trying to navigate
+                // to a new page anyway, we just ignore those false success callbacks.
+                // We have a listener for the window's "beforeunload" event that sets
+                // this flag.
+
+                if (Tapestry.windowUnloaded)
+                    return;
+
                 if (! response.request.success())
                 {
                     Tapestry.ajaxError("Server request was unsuccesful. There may be a problem accessing the server.");
@@ -1327,7 +1336,6 @@
 /**
  * Manages a &lt;div&lt; (or other element) for dynamic updates.
  *
- * @param element
  */
 Tapestry.ZoneManager = Class.create({
     // spec are the parameters for the Zone:
@@ -1715,3 +1723,9 @@
 }
 
 Tapestry.onDOMLoaded(Tapestry.onDomLoadedCallback);
+
+// Ajax code needs to know to do nothing after the window is unloaded.
+Event.observe(window, "beforeunload", function()
+{
+    Tapestry.windowUnloaded = true;
+});

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ProgressiveDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ProgressiveDemo.tml?rev=748645&r1=748644&r2=748645&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ProgressiveDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ProgressiveDemo.tml Fri Feb 27 19:04:37 2009
@@ -1,28 +1,32 @@
 <t:border xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
           xmlns:p="tapestry:parameter">
 
+    <t:actionlink t:id="refresh">refresh</t:actionlink>
+
     <t:progressiveDisplay t:id="disp1">
         <p id="content1">
             Progressive Display content #1.
         </p>
     </t:progressiveDisplay>
 
-    <t:progressivedisplay t:id="disp2">
+    <t:progressivedisplay t:id="disp2" context="literal:Music Library">
 
         <p>
             Progressive display content #2.
         </p>
 
-        <h3 id="content2">Music Library</h3>
+        <h3 id="content2">${context2}</h3>
 
         <p>Time is ${now}.</p>
 
-        <t:progressivedisplay update="slidedown">
-
-
-            <t:grid inplace="true" t:id="music" source="musicLibrary.tracks"/>
+        <t:progressivedisplay t:id="progressiveGrid" update="slidedown">
 
         </t:progressivedisplay>
     </t:progressivedisplay>
 
+
+    <t:block>
+        <t:grid inplace="true" t:id="music" source="musicLibrary.tracks"/>
+    </t:block>
+
 </t:border>
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ProgressiveDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ProgressiveDemo.java?rev=748645&r1=748644&r2=748645&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ProgressiveDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ProgressiveDemo.java Fri Feb 27 19:04:37 2009
@@ -14,7 +14,9 @@
 
 package org.apache.tapestry5.integration.app1.pages;
 
+import org.apache.tapestry5.annotations.InjectComponent;
 import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.corelib.components.Grid;
 import org.apache.tapestry5.integration.app1.services.MusicLibrary;
 import org.apache.tapestry5.ioc.annotations.Inject;
 
@@ -26,8 +28,47 @@
     @Property
     private MusicLibrary musicLibrary;
 
+    @Property
+    private String context2;
+
+    @InjectComponent
+    private Grid music;
+
     public Date getNow()
     {
         return new Date();
     }
+
+
+    void onProgressiveDisplayFromDisp2(String context)
+    {
+        context2 = context;
+    }
+
+    Object onProgressiveDisplayFromProgressiveGrid()
+    {
+
+        // sleep(1000);
+
+        return music;
+    }
+
+    public static void sleep(int millis)
+    {
+        try
+        {
+            Thread.sleep(millis);
+        }
+        catch (Exception ex)
+        {
+        }
+    }
+
+
+    Object onActionFromRefresh()
+    {
+        // sleep(100);
+
+        return this;
+    }
 }