You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2011/03/16 19:03:00 UTC

svn commit: r1082238 - /myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PartialPageUtils.java

Author: gcrawford
Date: Wed Mar 16 18:03:00 2011
New Revision: 1082238

URL: http://svn.apache.org/viewvc?rev=1082238&view=rev
Log:
TRINIDAD-2061 add a utility method in PartialPageUtils to send a <noop/> ppr response

Thanks to Yuan

Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PartialPageUtils.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PartialPageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PartialPageUtils.java?rev=1082238&r1=1082237&r2=1082238&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PartialPageUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/PartialPageUtils.java Wed Mar 16 18:03:00 2011
@@ -18,6 +18,10 @@
  */
 package org.apache.myfaces.trinidadinternal.renderkit.core.xhtml;
 
+import java.io.IOException;
+
+import java.io.Writer;
+
 import java.util.Iterator;
 import java.util.Map;
 
@@ -26,6 +30,8 @@ import javax.faces.component.UIComponent
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 
+import javax.servlet.http.HttpServletResponse;
+
 import org.apache.myfaces.trinidad.context.Agent;
 import org.apache.myfaces.trinidad.context.RequestContext;
 
@@ -33,7 +39,9 @@ import org.apache.myfaces.trinidadintern
 
 import org.apache.myfaces.trinidad.context.RenderingContext;
 import org.apache.myfaces.trinidad.context.PartialPageContext;
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
 import org.apache.myfaces.trinidadinternal.renderkit.core.ppr.PartialPageContextImpl;
+import org.apache.myfaces.trinidadinternal.renderkit.core.ppr.XmlResponseWriter;
 
 /**
  * Utility methods for Renderers which support partial page rendering.
@@ -247,6 +255,40 @@ public final class PartialPageUtils
   {
     context.getAttributes().put(_OPTIMIZED_PPR_ENABLED_PROP, Boolean.TRUE);
   }
+  
+  
+  /**
+   * This method writes a <noop/> to the response. 
+   * 
+   * @param context the FacesContext
+   * @throws IOException 
+   */
+  public static void renderNoopResponse(FacesContext context) 
+    throws IOException
+  {
+    ExternalContext external = context.getExternalContext();
+    Writer writer = ExternalContextUtils.getResponseWriter(external);
+    Object response = external.getResponse();
+    
+    if (response instanceof HttpServletResponse) 
+    {
+      HttpServletResponse httpResponse = (HttpServletResponse) response;
+  
+      // Prevent caching
+      httpResponse.setHeader("Cache-Control", "no-cache");
+      httpResponse.setHeader("Pragma", "no-cache");
+      httpResponse.setHeader("Expires", "-1");
+    }
+    
+    XmlResponseWriter xrw = new XmlResponseWriter(writer, "utf-8");
+    xrw.startDocument();
+
+    xrw.startElement("noop", null);
+    xrw.endElement("noop");      
+
+    xrw.endDocument();
+    xrw.close();
+  }
 
   /**
    * Returns the value of the PPR optimization parameter.  We currently support "on" and "off"