Author: hlship
Date: Thu Aug 11 00:17:23 2011
New Revision: 1156409
URL: http://svn.apache.org/viewvc?rev=1156409&view=rev
Log:
Add additional callback to AjaxResponseRenderer service
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/CombinedRenderCommand.java
- copied, changed from r1156308,
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/CombinedRenderCommand.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/JSONCallback.java
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/CombinedRenderCommand.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java?rev=1156409&r1=1156408&r2=1156409&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
Thu Aug 11 00:17:23 2011
@@ -10,6 +10,7 @@ import org.apache.tapestry5.runtime.Rend
import org.apache.tapestry5.services.PartialMarkupRenderer;
import org.apache.tapestry5.services.PartialMarkupRendererFilter;
import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
+import org.apache.tapestry5.services.ajax.JSONCallback;
import org.apache.tapestry5.services.ajax.JavaScriptCallback;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
@@ -32,31 +33,30 @@ public class AjaxResponseRendererImpl im
this.javaScriptSupport = javaScriptSupport;
}
- public void addRender(String clientId, Object renderer)
+ public AjaxResponseRenderer addRender(String clientId, Object renderer)
{
assert InternalUtils.isNonBlank(clientId);
assert renderer != null;
RenderCommand command = typeCoercer.coerce(renderer,
RenderCommand.class);
- // When a filter is added, it is assumed that some partial render will
occur. This covers the case where
- // a MultiZoneUpdate or a null is returned from the Ajax event handler
method.
+ addFilter(new SingleZonePartialRendererFilter(clientId, command,
queue, ajaxFormUpdateController));
- queue.forcePartialRenderInitialized();
- queue.addPartialMarkupRendererFilter(new
SingleZonePartialRendererFilter(clientId, command, queue,
ajaxFormUpdateController));
+ return this;
}
- public void addRender(ClientBodyElement zone)
+ public AjaxResponseRenderer addRender(ClientBodyElement zone)
{
assert zone != null;
addRender(zone.getClientId(), zone.getBody());
+
+ return this;
}
- public void addCallback(final JavaScriptCallback callback)
+ public AjaxResponseRenderer addCallback(final JavaScriptCallback callback)
{
- queue.forcePartialRenderInitialized();
- queue.addPartialMarkupRendererFilter(new PartialMarkupRendererFilter()
+ addFilter(new PartialMarkupRendererFilter()
{
public void renderMarkup(MarkupWriter writer, JSONObject reply,
PartialMarkupRenderer renderer)
{
@@ -65,5 +65,37 @@ public class AjaxResponseRendererImpl im
renderer.renderMarkup(writer, reply);
}
});
+
+ return this;
+ }
+
+ public AjaxResponseRenderer addFilter(PartialMarkupRendererFilter filter)
+ {
+ assert filter != null;
+
+ // When a filter is added, it is assumed that some partial render will
occur. This covers the case where
+ // a MultiZoneUpdate or a null is returned from the Ajax event handler
method, so there is not actual
+ // renderer (a default no-op renderer is supplied).
+
+ queue.forcePartialRenderInitialized();
+
+ queue.addPartialMarkupRendererFilter(filter);
+
+ return this;
+ }
+
+ public AjaxResponseRenderer addCallback(final JSONCallback callback)
+ {
+ addFilter(new PartialMarkupRendererFilter()
+ {
+ public void renderMarkup(MarkupWriter writer, JSONObject reply,
PartialMarkupRenderer renderer)
+ {
+ callback.run(reply);
+
+ renderer.renderMarkup(writer, reply);
+ }
+ });
+
+ return this;
}
}
Copied:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/CombinedRenderCommand.java
(from r1156308,
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/CombinedRenderCommand.java)
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/CombinedRenderCommand.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/CombinedRenderCommand.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/CombinedRenderCommand.java&r1=1156308&r2=1156409&rev=1156409&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/CombinedRenderCommand.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/CombinedRenderCommand.java
Thu Aug 11 00:17:23 2011
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry5.services.ajax;
+package org.apache.tapestry5.internal.services.ajax;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.runtime.RenderCommand;
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java?rev=1156409&r1=1156408&r2=1156409&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/SingleZonePartialRendererFilter.java
Thu Aug 11 00:17:23 2011
@@ -22,12 +22,12 @@ import org.apache.tapestry5.runtime.Rend
import org.apache.tapestry5.runtime.RenderQueue;
import org.apache.tapestry5.services.PartialMarkupRenderer;
import org.apache.tapestry5.services.PartialMarkupRendererFilter;
-import org.apache.tapestry5.services.ajax.CombinedRenderCommand;
/**
* Responsible for capturing the content for a single zone and storing it into
the JSON reply object.
*
* @see org.apache.tapestry5.ajax.MultiZoneUpdate
+ * @see
org.apache.tapestry5.services.ajax.AjaxResponseRenderer#addRender(String,
Object)
* @since 5.1.0.1
*/
public class SingleZonePartialRendererFilter implements
PartialMarkupRendererFilter
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java?rev=1156409&r1=1156408&r2=1156409&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/AjaxResponseRenderer.java
Thu Aug 11 00:17:23 2011
@@ -15,12 +15,12 @@
package org.apache.tapestry5.services.ajax;
import org.apache.tapestry5.ClientBodyElement;
+import org.apache.tapestry5.services.PartialMarkupRendererFilter;
/**
* Manages the rendering of a partial page render as part of an Ajax response.
This replaces
* the {@link org.apache.tapestry5.ajax.MultiZoneUpdate} introduced in
Tapestry 5.1. Much of the API is used to
- * queue behaviors that are deferred until the component event processing is
completed, at which
- * point a partial page render takes place, using queued data to construct the
overall response.
+ * queue behaviors that take effect when {@linkplain
org.apache.tapestry5.services.PartialMarkupRenderer partial markup rendering
takes place}.
* <p/>
* The implementation of this class provides {@link
org.apache.tapestry5.services.PartialMarkupRendererFilter} to
* the {@link org.apache.tapestry5.internal.services.PageRenderQueue}.
@@ -35,20 +35,40 @@ public interface AjaxResponseRenderer
* @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
*/
- void addRender(String clientId, Object renderer);
+ AjaxResponseRenderer addRender(String clientId, Object renderer);
/**
* 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).
+ * @return this renderer, for a fluid interface
*/
- void addRender(ClientBodyElement zone);
+ AjaxResponseRenderer addRender(ClientBodyElement zone);
/**
- * Queues a callback to execute during the partial markup render.
+ * 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
+ * @return this renderer, for a fluid interface
*/
- void addCallback(JavaScriptCallback callback);
+ AjaxResponseRenderer addCallback(JavaScriptCallback callback);
+
+ /**
+ * Adds a rendering filter. Dynamically added filters are only in place
during the handling of the current request, and come after any filters
+ * contributed to the {@link
org.apache.tapestry5.services.PartialMarkupRenderer} service.
+ *
+ * @return this renderer, for a fluid interface
+ */
+ AjaxResponseRenderer addFilter(PartialMarkupRendererFilter filter);
+
+ /**
+ * 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
+ * @return this renderer, for a fluid interface
+ */
+ AjaxResponseRenderer addCallback(JSONCallback callback);
}
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/JSONCallback.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/JSONCallback.java?rev=1156409&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/JSONCallback.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ajax/JSONCallback.java
Thu Aug 11 00:17:23 2011
@@ -0,0 +1,33 @@
+// 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
+//
+// 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
+// limitations under the License.
+
+package org.apache.tapestry5.services.ajax;
+
+import org.apache.tapestry5.json.JSONObject;
+
+/**
+ * A callback used with {@link AjaxResponseRenderer#addCallback(JSONCallback)}.
+ *
+ * @since 5.3
+ */
+public interface JSONCallback
+{
+ /**
+ * Modify the reply, typically by adding additional keys.
+ *
+ * @param reply the reply JSON object to be sent to the client
+ */
+ void run(JSONObject reply);
+
+}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy?rev=1156409&r1=1156408&r2=1156409&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
Thu Aug 11 00:17:23 2011
@@ -89,10 +89,6 @@ class AlertsTests extends SeleniumTestCa
waitForCSSSelectedElementToAppear "div.t-error"
- // Ah, Selenium, I love you. You make my day go so quicky. In any
case, this should work
- // clear as day, but doesn't, so it's commented out. I guess this just
goes to manual
- // testing.
-
assertText "css=div.t-error div.t-message-container", "ajax error
single"
click "link=Dismiss all"