Author: hlship
Date: Fri Feb 29 14:28:58 2008
New Revision: 632466
URL: http://svn.apache.org/viewvc?rev=632466&view=rev
Log:
TAPESTR-2209: JSONObject response contains additional {}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalConstants.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxComponentEventRequestHandler.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxPartialResponseRendererImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/JSONObjectEventResultProcessor.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ZoneDemo.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalConstants.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalConstants.java?rev=632466&r1=632465&r2=632466&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalConstants.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/InternalConstants.java
Fri Feb 29 14:28:58 2008
@@ -76,6 +76,13 @@
*/
public static final String IMMEDIATE_RESPONSE_PAGE_ATTRIBUTE =
"tapestry.immediate-response-page";
+ /**
+ * Required MIME type for JSON responses. If this MIME type is not used,
the client-side
+ * Prototype code will not recognize the response as JSON, and the
Ajax.Response.responseJSON property
+ * will be null.
+ */
+ public static final String JSON_MIME_TYPE = "application/json";
+
private InternalConstants()
{
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxComponentEventRequestHandler.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxComponentEventRequestHandler.java?rev=632466&r1=632465&r2=632466&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxComponentEventRequestHandler.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxComponentEventRequestHandler.java
Fri Feb 29 14:28:58 2008
@@ -93,11 +93,20 @@
_environment.pop(ComponentEventResultProcessor.class);
- if (_queue.isPartialRenderInitialized())
+ // isAborted() will be true when a non-null value was returned from
the event handler method.
+ // Some return types will initialize the PageRenderQueue, others will
stream a response directly.
+
+ if (callback.isAborted())
{
- _partialRenderer.renderPartialPageMarkup();
+ if (_queue.isPartialRenderInitialized())
+ {
+ _partialRenderer.renderPartialPageMarkup();
+ }
+
return;
}
+
+ // Send an empty JSON reply if no value was returned from the
component event handler method.
JSONObject reply = new JSONObject();
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxPartialResponseRendererImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxPartialResponseRendererImpl.java?rev=632466&r1=632465&r2=632466&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxPartialResponseRendererImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/AjaxPartialResponseRendererImpl.java
Fri Feb 29 14:28:58 2008
@@ -55,7 +55,7 @@
InternalConstants.CONTENT_TYPE_ATTRIBUTE_NAME);
String charset =
pageContentType.getParameter(InternalConstants.CHARSET_CONTENT_TYPE_PARAMETER);
- ContentType contentType = new ContentType("application/json");
+ ContentType contentType = new
ContentType(InternalConstants.JSON_MIME_TYPE);
contentType.setParameter(InternalConstants.CHARSET_CONTENT_TYPE_PARAMETER,
charset);
MarkupWriter writer = _factory.newMarkupWriter(pageContentType);
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/JSONObjectEventResultProcessor.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/JSONObjectEventResultProcessor.java?rev=632466&r1=632465&r2=632466&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/JSONObjectEventResultProcessor.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/JSONObjectEventResultProcessor.java
Fri Feb 29 14:28:58 2008
@@ -17,6 +17,7 @@
import org.apache.tapestry.json.JSONObject;
import org.apache.tapestry.services.ComponentEventResultProcessor;
import org.apache.tapestry.services.Response;
+import org.apache.tapestry.internal.InternalConstants;
import java.io.IOException;
import java.io.PrintWriter;
@@ -38,7 +39,7 @@
public void processResultValue(JSONObject value) throws IOException
{
- PrintWriter pw = _response.getPrintWriter("text/javascript");
+ PrintWriter pw =
_response.getPrintWriter(InternalConstants.JSON_MIME_TYPE);
pw.print(value.toString());
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneDemo.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneDemo.tml?rev=632466&r1=632465&r2=632466&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneDemo.tml Fri Feb
29 14:28:58 2008
@@ -39,6 +39,9 @@
<li t:type="loop" source="names" value="name">
<t:actionlink t:id="select" context="name" zone="output">Select
"${name}"</t:actionlink>
</li>
+ <li>
+ <t:actionlink t:id="JSON" zone="output">Direct JSON
response</t:actionlink>
+ </li>
</ul>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=632466&r1=632465&r2=632466&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Fri Feb 29 14:28:58 2008
@@ -1244,10 +1244,12 @@
// HTML entities.
click("select_0");
- // And that's as far as we can go currently, because
+ // And that's as far as we can go currently, because
// of limitations in Selenium 0.8.3 and bugs in Selenium 0.9.2.
- // assertTextPresent("Selected: Mr. <Roboto>");
+ // assertTextPresent("Selected: Mr. <Roboto>");
+
+ click("link=Direct JSON response");
}
/**
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ZoneDemo.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ZoneDemo.java?rev=632466&r1=632465&r2=632466&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ZoneDemo.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ZoneDemo.java
Fri Feb 29 14:28:58 2008
@@ -20,6 +20,7 @@
import org.apache.tapestry.corelib.components.Form;
import org.apache.tapestry.integration.app1.data.RegistrationData;
import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.json.JSONObject;
import org.slf4j.Logger;
public class ZoneDemo
@@ -35,7 +36,7 @@
@ApplicationState
private RegistrationData _registration;
- private static final String[] NAMES = {"Fred & Wilma", "Mr. <Roboto>",
"Grim Fandango", "Registration"};
+ private static final String[] NAMES = { "Fred & Wilma", "Mr. <Roboto>",
"Grim Fandango", "Registration" };
@Inject
private Block _showName;
@@ -90,5 +91,14 @@
public RegistrationData getRegistration()
{
return _registration;
+ }
+
+ Object onActionFromJSON()
+ {
+ JSONObject response = new JSONObject();
+
+ response.put("content", "Directly coded JSON content");
+
+ return response;
}
}