You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2008/04/19 10:17:50 UTC
svn commit: r649769 - in
/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago:
ajax/api/AjaxResponse.java ajax/api/AjaxResponseRenderer.java
webapp/TobagoResponseJsonWriterImpl.java webapp/TobagoResponseWriterImpl.java
Author: bommel
Date: Sat Apr 19 01:17:49 2008
New Revision: 649769
URL: http://svn.apache.org/viewvc?rev=649769&view=rev
Log:
(TOBAGO-653) Create a own JsonResponseWriter for dojo ajax requests
Added:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java (with props)
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponse.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponseRenderer.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponse.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponse.java?rev=649769&r1=649768&r2=649769&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponse.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponse.java Sat Apr 19 01:17:49 2008
@@ -55,6 +55,18 @@
}
}
+ public AjaxResponse(String ajaxId, int responseCode, String html, String javaScript) {
+ this.responseCode = responseCode;
+ this.ajaxId = ajaxId;
+ if (responseCode == CODE_SUCCESS) {
+ this.html = html;
+ this.javaScript = javaScript;
+ } else {
+ this.html = "";
+ this.javaScript = "";
+ }
+ }
+
public int getResponseCode() {
return responseCode;
}
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponseRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponseRenderer.java?rev=649769&r1=649768&r2=649769&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponseRenderer.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxResponseRenderer.java Sat Apr 19 01:17:49 2008
@@ -32,6 +32,7 @@
import org.apache.myfaces.tobago.util.ResponseUtils;
import org.apache.myfaces.tobago.util.JndiUtils;
import org.apache.myfaces.tobago.compat.FacesUtils;
+import org.apache.myfaces.tobago.webapp.TobagoResponseJsonWriterImpl;
import javax.faces.FactoryFinder;
import javax.faces.application.StateManager;
@@ -123,22 +124,25 @@
private AjaxResponse renderComponent(FacesContext facesContext, RenderKit renderKit, String clientId,
AjaxComponent component) throws IOException {
FastStringWriter content = new FastStringWriter();
- ResponseWriter contentWriter = renderKit.createResponseWriter(content, null, null);
+ ResponseWriter contentWriter = renderKit.createResponseWriter(content, contentType, null);
facesContext.setResponseWriter(contentWriter);
if (LOG.isDebugEnabled()) {
LOG.debug("write ajax response for " + component);
}
try {
- // TODO: invokeOnComponent()
FacesUtils.invokeOnComponent(facesContext, facesContext.getViewRoot(), clientId, callback);
- //ComponentUtil.invokeOnComponent(facesContext, clientId, (UIComponent) component, callback);
} catch (EmptyStackException e) {
LOG.error(" content = \"" + content.toString() + "\"");
throw e;
}
- return new AjaxResponse(clientId, callback.getResponseCode(), content.toString());
+ if (contentWriter instanceof TobagoResponseJsonWriterImpl) {
+ return new AjaxResponse(clientId, callback.getResponseCode(), content.toString(),
+ ((TobagoResponseJsonWriterImpl) contentWriter).getJavascript());
+ } else {
+ return new AjaxResponse(clientId, callback.getResponseCode(), content.toString());
+ }
}
private void writeResponseReload(FacesContext facesContext)
@@ -217,7 +221,10 @@
buffer.append(" ajaxPart_").append(i++);
buffer.append(": ");
buffer.append(part.toJson());
+ System.err.println("########################################");
+ System.err.println(part.toJson());
}
+
buffer.append("\n}\n");
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java?rev=649769&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java Sat Apr 19 01:17:49 2008
@@ -0,0 +1,40 @@
+package org.apache.myfaces.tobago.webapp;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import org.apache.myfaces.tobago.util.FastStringWriter;
+
+import java.io.Writer;
+import java.io.IOException;
+
+public class TobagoResponseJsonWriterImpl extends TobagoResponseWriterImpl {
+ private Writer javascriptWriter;
+ public TobagoResponseJsonWriterImpl(Writer writer, String contentType, String characterEncoding) {
+ super(writer, contentType, characterEncoding);
+ this.javascriptWriter = new FastStringWriter();
+ }
+
+ public void writeJavascript(String script) throws IOException {
+ writeInternal(javascriptWriter, script);
+ writeInternal(javascriptWriter, "\n");
+ }
+
+ public String getJavascript() {
+ return javascriptWriter.toString();
+ }
+}
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseJsonWriterImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java?rev=649769&r1=649768&r2=649769&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java Sat Apr 19 01:17:49 2008
@@ -131,6 +131,10 @@
@Override
public void write(String string) throws IOException {
+ writeInternal(writer, string);
+ }
+
+ protected final void writeInternal(Writer writer, String string) throws IOException {
closeOpenTag();
writer.write(string);
}
@@ -215,6 +219,10 @@
public void startElement(final String name, final UIComponent currentComponent)
throws IOException {
+ startElementInternal(writer, name, currentComponent);
+ }
+
+ protected final void startElementInternal(Writer writer, String name, UIComponent currentComponent) throws IOException {
this.component = currentComponent;
stack.push(name);
// closeOpenTag();
@@ -227,6 +235,10 @@
}
public void endElement(final String name) throws IOException {
+ endElementInternal(writer, name);
+ }
+
+ protected final void endElementInternal(Writer writer, String name) throws IOException {
if (LOG.isDebugEnabled()) {
LOG.debug("end Element: " + name);
}
@@ -309,6 +321,10 @@
public void writeAttribute(final String name, final String value, final boolean escape)
throws IOException {
+ writeAttributeInternal(writer, name, value, escape);
+ }
+
+ protected final void writeAttributeInternal(Writer write, String name, String value, boolean escape) throws IOException {
if (!startStillOpen) {
String trace = getCallingClassStackTraceElementString();
String error = "Cannot write attribute when start-tag not open. "