myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfreed...@apache.org
Subject svn commit: r950147 - in /myfaces/portlet-bridge/core/tags/1.0.0: examples/guessNumberMojarraFilter/src/main/java/org/apache/myfaces/portlet/faces/application/ examples/guessNumberMyFacesFilter/src/main/java/org/apache/myfaces/portlet/faces/application...
Date Tue, 01 Jun 2010 16:32:47 GMT
Author: mfreedman
Date: Tue Jun  1 16:32:47 2010
New Revision: 950147

URL: http://svn.apache.org/viewvc?rev=950147&view=rev
Log:
PORTLETBRIDGE-143: WriteBehindResponse mechanism(s) not working properly. For 1.0.0 PB fixed
requires the servletFilters in the examples to set the externalContext response as the Faces
impls get this response to see if it implements the Faces impl dependent write behind mechanism.
 This also required a change to the bridge's External Context.set/getReponse as it now has
to allow a non-portlet response be set/get.

Modified:
    myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMojarraFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMojarraRenderFilter.java
    myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMyFacesFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMyFacesRenderFilter.java
    myfaces/portlet-bridge/core/tags/1.0.0/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java

Modified: myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMojarraFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMojarraRenderFilter.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMojarraFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMojarraRenderFilter.java?rev=950147&r1=950146&r2=950147&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMojarraFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMojarraRenderFilter.java
(original)
+++ myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMojarraFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMojarraRenderFilter.java
Tue Jun  1 16:32:47 2010
@@ -10,6 +10,9 @@ import java.io.Writer;
 
 import java.nio.ByteBuffer;
 
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
 import javax.portlet.faces.Bridge;
 
 import javax.servlet.Filter;
@@ -51,7 +54,16 @@ public class BridgeMojarraRenderFilter
     BridgeRenderFilterResponseWrapper wrapped = 
       new BridgeRenderFilterResponseWrapper((HttpServletResponse) response);
 
+    // temporarily set as the response object in the ExternalContext -- as the Mojarra ViewTag
+    // gets this instance to verify it can write after.
+    ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
+    Object currentResponse = extCtx.getResponse();
+    extCtx.setResponse(wrapped);
+    
     chain.doFilter(request, wrapped);
+    
+    // reset the ExternalContext response
+    extCtx.setResponse(currentResponse);
 
     // wrap the response as a JSF RI wrapped response
     // execute the chain

Modified: myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMyFacesFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMyFacesRenderFilter.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMyFacesFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMyFacesRenderFilter.java?rev=950147&r1=950146&r2=950147&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMyFacesFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMyFacesRenderFilter.java
(original)
+++ myfaces/portlet-bridge/core/tags/1.0.0/examples/guessNumberMyFacesFilter/src/main/java/org/apache/myfaces/portlet/faces/application/BridgeMyFacesRenderFilter.java
Tue Jun  1 16:32:47 2010
@@ -10,6 +10,9 @@ import java.io.Writer;
 
 import java.nio.ByteBuffer;
 
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
 import javax.portlet.faces.Bridge;
 
 import javax.servlet.Filter;
@@ -48,10 +51,20 @@ public class BridgeMyFacesRenderFilter
     }
 
     // otherwise try and support render after
+
     BridgeRenderFilterResponseWrapper wrapped = 
       new BridgeRenderFilterResponseWrapper((HttpServletResponse) response);
 
+    // temporarily set as the response object in the ExternalContext -- as the Mojarra ViewTag
+    // gets this instance to verify it can write after.
+    ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
+    Object currentResponse = extCtx.getResponse();
+    extCtx.setResponse(wrapped);
+    
     chain.doFilter(request, wrapped);
+    
+    // reset the ExternalContext response
+    extCtx.setResponse(currentResponse);
 
     // wrap the response as a JSF RI wrapped response
     // execute the chain
@@ -284,7 +297,13 @@ public class BridgeMyFacesRenderFilter
     public void clearWrappedResponse() throws IOException {
       resetBuffers();
     }
-
+    
+    public void flushToWrappedResponse()
+    throws IOException
+    {
+      flushContentToWrappedResponse();
+    }
+    
     /**
      * Flush the current buffered content to the wrapped
      * response (this could be a Servlet or Portlet response)

Modified: myfaces/portlet-bridge/core/tags/1.0.0/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/tags/1.0.0/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java?rev=950147&r1=950146&r2=950147&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/tags/1.0.0/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
(original)
+++ myfaces/portlet-bridge/core/tags/1.0.0/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
Tue Jun  1 16:32:47 2010
@@ -113,6 +113,8 @@ public class PortletExternalContextImpl
   private PortletContext mPortletContext;
   private PortletRequest mPortletRequest;
   private PortletResponse mPortletResponse;
+  private Object mTempNonPortletResponse;
+
   
   private String mPortletName;
 
@@ -788,7 +790,14 @@ public class PortletExternalContextImpl
   @Override
   public Object getResponse()
   {
-    return mPortletResponse;
+    if (mTempNonPortletResponse != null)
+    {
+      return mTempNonPortletResponse;
+    }
+    else
+    {
+      return mPortletResponse;
+    }
   }
 
   @Override
@@ -1290,7 +1299,20 @@ public class PortletExternalContextImpl
   @Override
   public void setResponse(Object response)
   {
-    mPortletResponse = (PortletResponse) response;
+    // Early versions of Mojarra 1.2 check the externalContext response object to see if
it implements its writeBehind API (using instanceof)
+    // And since protlet 1.0 didn't support portlet filters/wrappers the bridge allows one
to implement this via a servlet filter/wrapper.
+    // In such circumstances the Mojarra servlet response wrapper has to be set as the current
externalContext response so that things run properly
+    // Hence we need to account/allow for non-portlet response objects here (temporarily)
+    if (response instanceof PortletResponse)
+    {
+      mPortletResponse = (PortletResponse) response;
+      // clear if set so its not used in getResponse()
+      mTempNonPortletResponse = null;
+    }
+    else
+    {
+      mTempNonPortletResponse = response;
+    }
   }
 
   /**



Mime
View raw message