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 2014/10/30 00:02:22 UTC

git commit: Add an easier way to perform a partial page render outside of the standard AjaxComponentEventRequestHandler

Repository: tapestry-5
Updated Branches:
  refs/heads/master 6f4c5640c -> b7f60e28e


Add an easier way to perform a partial page render outside of the standard AjaxComponentEventRequestHandler


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

Branch: refs/heads/master
Commit: b7f60e28e959b0250aac056f7e559515e75901d9
Parents: 6f4c564
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Wed Oct 29 16:02:14 2014 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed Oct 29 16:02:14 2014 -0700

----------------------------------------------------------------------
 .../AjaxPartialResponseRendererImpl.java        |  5 +++
 .../internal/services/PageRenderQueueImpl.java  | 13 ++++++--
 .../services/ajax/AjaxResponseRendererImpl.java | 30 ++++++++++++++----
 .../services/ajax/AjaxResponseRenderer.java     | 32 ++++++++++++++------
 4 files changed, 63 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b7f60e28/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
index 22ffce9..4b95f37 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
@@ -81,6 +81,11 @@ public class AjaxPartialResponseRendererImpl implements AjaxPartialResponseRende
 
                 String pageName = (String) request.getAttribute(InternalConstants.PAGE_NAME_ATTRIBUTE_NAME);
 
+                if (pageName == null)
+                {
+                    throw new IllegalStateException("The active page name has not been specified.");
+                }
+
                 MarkupWriter writer = factory.newPartialMarkupWriter(pageName);
 
                 // ... and here, the pipeline eventually reaches the PRQ to let it render the root render command.

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b7f60e28/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
index 34a997d..a61e15c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
@@ -1,5 +1,3 @@
-// Copyright 2007, 2008, 2010, 2011 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
@@ -97,11 +95,20 @@ public class PageRenderQueueImpl implements PageRenderQueue
     {
         assert renderer != null;
 
+        checkQueue();
+
         partialRenderInitialized = true;
 
         queue.push(renderer);
     }
 
+    private void checkQueue()
+    {
+        if (queue == null) {
+            throw new IllegalStateException("The page used as the basis for partial rendering has not been set.");
+        }
+    }
+
     public Page getRenderingPage()
     {
         return page;
@@ -125,6 +132,8 @@ public class PageRenderQueueImpl implements PageRenderQueue
 
     public void renderPartial(MarkupWriter writer, JSONObject reply)
     {
+        checkQueue();
+
         PartialMarkupRenderer terminator = new PartialMarkupRenderer()
         {
             public void renderMarkup(MarkupWriter writer, JSONObject reply)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b7f60e28/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
index b263f7c..6fa41cb 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
@@ -1,5 +1,3 @@
-//  Copyright 2011, 2013, 2014 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
@@ -17,12 +15,16 @@ import org.apache.tapestry5.ClientBodyElement;
 import org.apache.tapestry5.MarkupWriter;
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.services.PageRenderQueue;
+import org.apache.tapestry5.internal.services.PageSource;
+import org.apache.tapestry5.internal.services.RequestPageCache;
+import org.apache.tapestry5.internal.structure.Page;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.runtime.RenderCommand;
 import org.apache.tapestry5.services.PartialMarkupRenderer;
 import org.apache.tapestry5.services.PartialMarkupRendererFilter;
+import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
 import org.apache.tapestry5.services.ajax.JSONCallback;
 import org.apache.tapestry5.services.ajax.JavaScriptCallback;
@@ -39,12 +41,18 @@ public class AjaxResponseRendererImpl implements AjaxResponseRenderer
 
     private final JavaScriptSupport javaScriptSupport;
 
-    public AjaxResponseRendererImpl(PageRenderQueue queue, AjaxFormUpdateController ajaxFormUpdateController, TypeCoercer typeCoercer, JavaScriptSupport javaScriptSupport)
+    private final RequestPageCache requestPageCache;
+
+    private final Request request;
+
+    public AjaxResponseRendererImpl(PageRenderQueue queue, AjaxFormUpdateController ajaxFormUpdateController, TypeCoercer typeCoercer, JavaScriptSupport javaScriptSupport, RequestPageCache requestPageCache, Request request)
     {
         this.queue = queue;
         this.ajaxFormUpdateController = ajaxFormUpdateController;
         this.typeCoercer = typeCoercer;
         this.javaScriptSupport = javaScriptSupport;
+        this.requestPageCache = requestPageCache;
+        this.request = request;
     }
 
     public AjaxResponseRenderer addRender(String clientId, Object renderer)
@@ -64,14 +72,14 @@ public class AjaxResponseRendererImpl implements AjaxResponseRenderer
         assert zone != null;
 
         final String clientId = zone.getClientId();
-        
+
         if (clientId == null)
         {
             throw new IllegalArgumentException(
                     "Attempt to render a ClientBodyElement, probably a Zone, with a null clientId. "
-                    + "You can solve this by using the id parameter.");
+                            + "You can solve this by using the id parameter.");
         }
-        
+
         addRender(clientId, zone.getBody());
 
         return this;
@@ -157,4 +165,14 @@ public class AjaxResponseRendererImpl implements AjaxResponseRenderer
 
         return this;
     }
+
+    @Override
+    public void setupPartial(String pageName)
+    {
+        Page page = requestPageCache.get(pageName);
+
+        queue.setRenderingPage(page);
+
+        request.setAttribute(InternalConstants.PAGE_NAME_ATTRIBUTE_NAME, page.getName());
+    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b7f60e28/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
index 7898a93..aae2b9f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
@@ -1,5 +1,3 @@
-// Copyright 2011 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
@@ -32,9 +30,11 @@ public interface AjaxResponseRenderer
     /**
      * Queues the renderer to render markup for the client-side element with the provided id.
      *
-     * @param clientId client id of zone to update with the content from the renderer
-     * @param renderer a {@link org.apache.tapestry5.Block}, {@link org.apache.tapestry5.runtime.Component} or other object that can be
-     *                 {@linkplain org.apache.tapestry5.ioc.services.TypeCoercer coerced} to  {@link org.apache.tapestry5.runtime.RenderCommand}.
+     * @param clientId
+     *         client id of zone to update with the content from the renderer
+     * @param renderer
+     *         a {@link org.apache.tapestry5.Block}, {@link org.apache.tapestry5.runtime.Component} or other object that can be
+     *         {@linkplain org.apache.tapestry5.ioc.services.TypeCoercer coerced} to  {@link org.apache.tapestry5.runtime.RenderCommand}.
      * @return the renderer, for a fluid interface
      */
     AjaxResponseRenderer addRender(String clientId, Object renderer);
@@ -42,7 +42,8 @@ public interface AjaxResponseRenderer
     /**
      * Queues an update to the zone, using the zone's body as the new content.
      *
-     * @param zone the element that contains both a client id and a body (this is primarily used to represent a {@link org.apache.tapestry5.corelib.components.Zone} component).
+     * @param zone
+     *         the element that contains both a client id and a body (this is primarily used to represent a {@link org.apache.tapestry5.corelib.components.Zone} component).
      * @return this renderer, for a fluid interface
      */
     AjaxResponseRenderer addRender(ClientBodyElement zone);
@@ -51,7 +52,8 @@ public interface AjaxResponseRenderer
      * Queues a callback to execute during the partial markup render. The callback is {@linkplain #addFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) added as a filter}; the
      * callback is invoked before the rest of the rendering pipeline is invoked.
      *
-     * @param callback object to be invoked
+     * @param callback
+     *         object to be invoked
      * @return this renderer, for a fluid interface
      */
     AjaxResponseRenderer addCallback(JavaScriptCallback callback);
@@ -60,7 +62,8 @@ public interface AjaxResponseRenderer
      * Queues a callback to execute during the partial markup render. . The callback is {@linkplain #addFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) added as a filter}; the
      * callback is invoked before the rest of the rendering pipeline is invoked.
      *
-     * @param callback object to be invoked
+     * @param callback
+     *         object to be invoked
      * @return this renderer, for a fluid interface
      */
     AjaxResponseRenderer addCallback(Runnable callback);
@@ -77,8 +80,19 @@ public interface AjaxResponseRenderer
      * Queues a callback to execute during the partial markup render. The callback is {@linkplain #addFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) added as a filter};
      * the callback is invoked before the rest of the rendering pipeline is invoked.
      *
-     * @param callback object o be invoked
+     * @param callback
+     *         object o be invoked
      * @return this renderer, for a fluid interface
      */
     AjaxResponseRenderer addCallback(JSONCallback callback);
+
+    /**
+     * Initializes partial response rendering by identifying the page "responsible" for the response. This is mostly
+     * used for selecting the character set for the response.
+     *
+     * @param pageName
+     *         identifies page to render
+     * @since 5.4
+     */
+    void setupPartial(String pageName);
 }
\ No newline at end of file