tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [2/2] git commit: When an Ajax component event request handler returns a JSONObject, pass that through the whole pipline to get the partial-page-rendering data injected into the response
Date Tue, 20 Nov 2012 00:42:11 GMT
When an Ajax component event request handler returns a JSONObject, pass that through the whole
pipline to get the partial-page-rendering data injected into the response


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

Branch: refs/heads/5.4-js-rewrite
Commit: 5687849849332fbf8bc33ff14168e714682b8cae
Parents: b0d52d3
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Mon Nov 19 16:41:33 2012 -0800
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Mon Nov 19 16:41:33 2012 -0800

----------------------------------------------------------------------
 .../services/AjaxComponentEventRequestHandler.java |    9 ++--
 .../services/AjaxPartialResponseRenderer.java      |   16 ++++++-
 .../services/AjaxPartialResponseRendererImpl.java  |   14 ++++--
 .../services/JSONObjectEventResultProcessor.java   |   38 +++------------
 4 files changed, 36 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56878498/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
index dafd4c6..028f3b5 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2010, 2011 The Apache Software Foundation
+// Copyright 2007, 2008, 2010, 2011, 2012 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.
@@ -135,10 +135,9 @@ public class AjaxComponentEventRequestHandler implements ComponentEventRequestHa
         if (wasInvoked) { return; }
 
         // Send an empty JSON reply if no value was returned from the component event handler
method.
-        // This is the typical behavior when an Ajax component event handler returns null.
+        // This is the typical behavior when an Ajax component event handler returns null.
It still
+        // will go through a pipeline that will add information related to partial page rendering.
 
-        JSONObject reply = new JSONObject();
-
-        resultProcessor.processResultValue(reply);
+        resultProcessor.processResultValue(new JSONObject());
     }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56878498/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
index 249476b..2534c80 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRenderer.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2012 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.
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry5.internal.services;
 
+import org.apache.tapestry5.json.JSONObject;
+
 import java.io.IOException;
 
 /**
@@ -32,4 +34,16 @@ public interface AjaxPartialResponseRenderer
      * should precede this call.
      */
     void renderPartialPageMarkup() throws IOException;
+
+    /**
+     * Used to render the partial response using a base reply object, to which any Tapestry-related
+     * information (usually related to zone updates and initializations) will be added. In
effect, this]
+     * "enhances" the reply, which contains just data, to include UI aspects that are handled
by client-side
+     * code on the client.
+     *
+     * @param reply
+     * @throws IOException
+     * @since 5.4
+     */
+    void renderPartialPageMarkup(JSONObject reply) throws IOException;
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56878498/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 6155879..7cd0eda 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
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010, 2011, 2012 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.
@@ -66,8 +66,11 @@ public class AjaxPartialResponseRendererImpl implements AjaxPartialResponseRende
         this.environment = environment;
     }
 
-    public void renderPartialPageMarkup() throws IOException
+    @Override
+    public void renderPartialPageMarkup(JSONObject reply) throws IOException
     {
+        assert reply != null;
+
         environment.cloak();
 
         try
@@ -82,8 +85,6 @@ public class AjaxPartialResponseRendererImpl implements AjaxPartialResponseRende
 
             MarkupWriter writer = factory.newPartialMarkupWriter(pageContentType);
 
-            JSONObject reply = new JSONObject();
-
             // ... and here, the pipeline eventually reaches the PRQ to let it render the
root render command.
 
             partialMarkupRenderer.renderMarkup(writer, reply);
@@ -98,4 +99,9 @@ public class AjaxPartialResponseRendererImpl implements AjaxPartialResponseRende
             environment.decloak();
         }
     }
+
+    public void renderPartialPageMarkup() throws IOException
+    {
+        renderPartialPageMarkup(new JSONObject());
+    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/56878498/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JSONObjectEventResultProcessor.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JSONObjectEventResultProcessor.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JSONObjectEventResultProcessor.java
index c62f19c..7ec474f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JSONObjectEventResultProcessor.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JSONObjectEventResultProcessor.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2007, 2008, 2010, 2012 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.
@@ -14,16 +14,10 @@
 
 package org.apache.tapestry5.internal.services;
 
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import org.apache.tapestry5.ContentType;
-import org.apache.tapestry5.SymbolConstants;
-import org.apache.tapestry5.internal.InternalConstants;
-import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.ComponentEventResultProcessor;
-import org.apache.tapestry5.services.Response;
+
+import java.io.IOException;
 
 /**
  * Implementation of {@link ComponentEventResultProcessor} for {@link org.apache.tapestry5.json.JSONObject},
allowing a
@@ -32,33 +26,15 @@ import org.apache.tapestry5.services.Response;
  */
 public class JSONObjectEventResultProcessor implements ComponentEventResultProcessor<JSONObject>
 {
-    private final Response response;
-
-    private final String outputEncoding;
-
-    private final boolean compactJSON;
+    private final AjaxPartialResponseRenderer ajaxPartialResponseRenderer;
 
-    public JSONObjectEventResultProcessor(Response response,
-
-    @Symbol(SymbolConstants.CHARSET)
-    String outputEncoding,
-
-    @Symbol(SymbolConstants.COMPACT_JSON)
-    boolean compactJSON)
+    public JSONObjectEventResultProcessor(AjaxPartialResponseRenderer ajaxPartialResponseRenderer)
     {
-        this.response = response;
-        this.outputEncoding = outputEncoding;
-        this.compactJSON = compactJSON;
+        this.ajaxPartialResponseRenderer = ajaxPartialResponseRenderer;
     }
 
     public void processResultValue(JSONObject value) throws IOException
     {
-        ContentType contentType = new ContentType(InternalConstants.JSON_MIME_TYPE, outputEncoding);
-
-        PrintWriter pw = response.getPrintWriter(contentType.toString());
-
-        value.print(pw, compactJSON);
-
-        pw.close();
+        ajaxPartialResponseRenderer.renderPartialPageMarkup(value);
     }
 }


Mime
View raw message