tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [1/4] git commit: TAP5-1984: Do not invoke AjaxResponseRenderer callbacks when the response is an Ajax redirect
Date Fri, 19 Jul 2013 23:09:35 GMT
Updated Branches:
  refs/heads/master 1cbec694d -> 22a6f129e


TAP5-1984: Do not invoke AjaxResponseRenderer callbacks when the response is an Ajax redirect


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

Branch: refs/heads/master
Commit: cba4eea6d0b0e2491fe44e8426e7eff8d5cc3768
Parents: 1cbec69
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Fri Jul 19 15:28:43 2013 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Fri Jul 19 15:28:43 2013 -0700

----------------------------------------------------------------------
 .../services/ajax/AjaxResponseRendererImpl.java | 50 ++++++++++++++++----
 1 file changed, 42 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/cba4eea6/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 98a0cc5..6d3b329 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,7 +1,21 @@
+//  Copyright 2011, 2013 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
+
 package org.apache.tapestry5.internal.services.ajax;
 
 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.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.services.TypeCoercer;
@@ -62,9 +76,9 @@ public class AjaxResponseRendererImpl implements AjaxResponseRenderer
         {
             public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer
renderer)
             {
-                callback.run(javaScriptSupport);
-
                 renderer.renderMarkup(writer, reply);
+
+                callback.run(javaScriptSupport);
             }
         });
 
@@ -79,9 +93,9 @@ public class AjaxResponseRendererImpl implements AjaxResponseRenderer
         {
             public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer
renderer)
             {
-                callback.run();
-
                 renderer.renderMarkup(writer, reply);
+
+                callback.run();
             }
         });
 
@@ -89,11 +103,31 @@ public class AjaxResponseRendererImpl implements AjaxResponseRenderer
         return this;
     }
 
-    public AjaxResponseRenderer addFilter(PartialMarkupRendererFilter filter)
+    private boolean isRedirect(JSONObject reply)
+    {
+
+        return reply.has(InternalConstants.PARTIAL_KEY) &&
+                reply.in(InternalConstants.PARTIAL_KEY).has("redirectURL");
+    }
+
+    public AjaxResponseRenderer addFilter(final PartialMarkupRendererFilter filter)
     {
         assert filter != null;
 
-        queue.addPartialMarkupRendererFilter(filter);
+        queue.addPartialMarkupRendererFilter(new PartialMarkupRendererFilter()
+        {
+            public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer
delete)
+            {
+                if (isRedirect(reply))
+                {
+                    // Bypass the callback.
+                    delete.renderMarkup(writer, reply);
+                    return;
+                }
+
+                filter.renderMarkup(writer, reply, delete);
+            }
+        });
 
         return this;
     }
@@ -106,9 +140,9 @@ public class AjaxResponseRendererImpl implements AjaxResponseRenderer
         {
             public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer
renderer)
             {
-                callback.run(reply);
-
                 renderer.renderMarkup(writer, reply);
+
+                callback.run(reply);
             }
         });
 


Mime
View raw message