You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/04/13 20:07:04 UTC

svn commit: r933725 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: context/servlet/ lifecycle/ view/jsp/

Author: lu4242
Date: Tue Apr 13 18:07:04 2010
New Revision: 933725

URL: http://svn.apache.org/viewvc?rev=933725&view=rev
Log:
MYFACES-2654 Trinidad ajax-branch does not work with MyFaces2

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/HttpServletResponseSwitch.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ResponseSwitch.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletResponseSwitch.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/HttpServletResponseSwitch.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/HttpServletResponseSwitch.java?rev=933725&r1=933724&r2=933725&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/HttpServletResponseSwitch.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/HttpServletResponseSwitch.java Tue Apr 13 18:07:04 2010
@@ -21,6 +21,7 @@ package org.apache.myfaces.context.servl
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import javax.faces.context.FacesContext;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletResponse;
@@ -40,8 +41,6 @@ import javax.servlet.http.HttpServletRes
  */
 public class HttpServletResponseSwitch extends HttpServletResponseWrapper implements ResponseSwitch
 {
-
-    private boolean _enabled = true;
     private PrintWriter _switchableWriter;
     private SwitchableOutputStream _switchableOutputStream;
 
@@ -56,7 +55,12 @@ public class HttpServletResponseSwitch e
      */
     public void setEnabled(boolean enabled)
     {
-        _enabled = enabled;
+        FacesContext.getCurrentInstance().getAttributes().put(ResponseSwitch.RESPONSE_SWITCH_ENABLED, enabled);
+    }
+    
+    public void setEnabled(FacesContext context, boolean enabled)
+    {
+        context.getAttributes().put(ResponseSwitch.RESPONSE_SWITCH_ENABLED, enabled);
     }
 
     /**
@@ -65,13 +69,23 @@ public class HttpServletResponseSwitch e
      */
     public boolean isEnabled()
     {
-        return _enabled;
+        Boolean enabled = (Boolean) FacesContext.getCurrentInstance().getAttributes()
+                              .get(ResponseSwitch.RESPONSE_SWITCH_ENABLED);
+        return enabled == null ? true : enabled;
     }
+    
+    public boolean isEnabled(FacesContext facesContext)
+    {
+        Boolean enabled = (Boolean) facesContext.getAttributes()
+            .get(ResponseSwitch.RESPONSE_SWITCH_ENABLED);
+        return enabled == null ? true : enabled;
+    }
+
 
     @Override
     public int getBufferSize()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             return super.getBufferSize();
         }
@@ -81,7 +95,7 @@ public class HttpServletResponseSwitch e
     @Override
     public boolean isCommitted()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             return super.isCommitted();
         }
@@ -91,7 +105,7 @@ public class HttpServletResponseSwitch e
     @Override
     public void reset()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             super.reset();
         }
@@ -100,7 +114,7 @@ public class HttpServletResponseSwitch e
     @Override
     public void resetBuffer()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             super.resetBuffer();
         }
@@ -109,7 +123,7 @@ public class HttpServletResponseSwitch e
     @Override
     public void flushBuffer() throws IOException
     {
-        if (_enabled)
+        if (isEnabled())
         {
             super.flushBuffer();
         }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java?rev=933725&r1=933724&r2=933725&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java Tue Apr 13 18:07:04 2010
@@ -329,7 +329,7 @@ public class PartialViewContextImpl exte
         ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(response);
         if (responseSwitch != null)
         {
-            responseSwitch.setEnabled(true);
+            responseSwitch.setEnabled(_facesContext, true);
         }
         
         //TODO process partial rendering

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ResponseSwitch.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ResponseSwitch.java?rev=933725&r1=933724&r2=933725&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ResponseSwitch.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ResponseSwitch.java Tue Apr 13 18:07:04 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.myfaces.context.servlet;
 
+import javax.faces.context.FacesContext;
+
 /**
  * Responses which can be enabled or disabled implement this interface.
  * 
@@ -26,11 +28,19 @@ package org.apache.myfaces.context.servl
  */
 public interface ResponseSwitch
 {
+    /**
+     * If the current ResponseSwitch is disabled, Boolean.FALSE will be stored in the
+     * FacesContext under this key, otherwise Boolean.TRUE will be stored
+     * ATTENTION: this constant is duplicate in UIViewRoot.
+     */
+    public static final String RESPONSE_SWITCH_ENABLED = "org.apache.myfaces.RESPONSE_SWITCH_ENABLED";
 
     /**
      * Enables or disables the Response's Writer and OutputStream.
      * @param enabled
      */
+    public void setEnabled(FacesContext facesContext, boolean enabled);
+    
     public void setEnabled(boolean enabled);
 
     /**
@@ -39,4 +49,6 @@ public interface ResponseSwitch
      */
     public boolean isEnabled();
     
+    public boolean isEnabled(FacesContext facesContext);
+    
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletResponseSwitch.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletResponseSwitch.java?rev=933725&r1=933724&r2=933725&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletResponseSwitch.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/ServletResponseSwitch.java Tue Apr 13 18:07:04 2010
@@ -21,6 +21,7 @@ package org.apache.myfaces.context.servl
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import javax.faces.context.FacesContext;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.ServletResponse;
 import javax.servlet.ServletResponseWrapper;
@@ -39,7 +40,6 @@ import javax.servlet.ServletResponseWrap
 public class ServletResponseSwitch extends ServletResponseWrapper implements ResponseSwitch
 {
 
-    private boolean _enabled = true;
     private PrintWriter _switchableWriter;
     private SwitchableOutputStream _switchableOutputStream;
 
@@ -54,7 +54,12 @@ public class ServletResponseSwitch exten
      */
     public void setEnabled(boolean enabled)
     {
-        _enabled = enabled;
+        FacesContext.getCurrentInstance().getAttributes().put(ResponseSwitch.RESPONSE_SWITCH_ENABLED, enabled);
+    }
+    
+    public void setEnabled(FacesContext context, boolean enabled)
+    {
+        context.getAttributes().put(ResponseSwitch.RESPONSE_SWITCH_ENABLED, enabled);
     }
 
     /**
@@ -63,13 +68,22 @@ public class ServletResponseSwitch exten
      */
     public boolean isEnabled()
     {
-        return _enabled;
+        Boolean enabled = (Boolean) FacesContext.getCurrentInstance().getAttributes()
+                              .get(ResponseSwitch.RESPONSE_SWITCH_ENABLED);
+        return enabled == null ? true : enabled;
+    }
+    
+    public boolean isEnabled(FacesContext facesContext)
+    {
+        Boolean enabled = (Boolean) facesContext.getAttributes()
+            .get(ResponseSwitch.RESPONSE_SWITCH_ENABLED);
+        return enabled == null ? true : enabled;
     }
 
     @Override
     public int getBufferSize()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             return super.getBufferSize();
         }
@@ -79,7 +93,7 @@ public class ServletResponseSwitch exten
     @Override
     public boolean isCommitted()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             return super.isCommitted();
         }
@@ -89,7 +103,7 @@ public class ServletResponseSwitch exten
     @Override
     public void reset()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             super.reset();
         }
@@ -98,7 +112,7 @@ public class ServletResponseSwitch exten
     @Override
     public void resetBuffer()
     {
-        if (_enabled)
+        if (isEnabled())
         {
             super.resetBuffer();
         }
@@ -107,7 +121,7 @@ public class ServletResponseSwitch exten
     @Override
     public void flushBuffer() throws IOException
     {
-        if (_enabled)
+        if (isEnabled())
         {
             super.flushBuffer();
         }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java?rev=933725&r1=933724&r2=933725&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java Tue Apr 13 18:07:04 2010
@@ -58,6 +58,14 @@ class RenderResponseExecutor implements 
         // JSF 2.0 section 2.2.6: if the current response
         // is a partial response, then there must be 
         // no content written outside of the f:view
+        // -= Leonardo Uribe =- This section was commented because it
+        // causes problems when a library try to override the default
+        // PartialViewContext implementation like trinidad. Since ajax
+        // stuff is only for facelets, there is no reason to keep this
+        // code here. Instead, this code was moved to 
+        // JspViewDeclarationLanguage.buildView, because it has more sense
+        // in that place.
+        /*
         if (facesContext.getPartialViewContext().isPartialRequest())
         {
             // try to get (or create) a ResponseSwitch and turn off the output
@@ -78,6 +86,7 @@ class RenderResponseExecutor implements 
                 responseSwitch.setEnabled(false);
             }
         }
+        */
         
         try
         {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java?rev=933725&r1=933724&r2=933725&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/jsp/JspViewDeclarationLanguage.java Tue Apr 13 18:07:04 2010
@@ -33,7 +33,9 @@ import javax.servlet.http.HttpServletRes
 import javax.servlet.jsp.jstl.core.Config;
 
 import org.apache.myfaces.application.jsp.ServletViewResponseWrapper;
+import org.apache.myfaces.context.servlet.ResponseSwitch;
 import org.apache.myfaces.shared_impl.view.JspViewDeclarationLanguageBase;
+import org.apache.myfaces.util.ExternalContextUtils;
 
 /**
  * @author Simon Lessard (latest modification by $Author: slessard $)
@@ -61,6 +63,28 @@ public class JspViewDeclarationLanguage 
     public void buildView(FacesContext context, UIViewRoot view) throws IOException
     {
         ExternalContext externalContext = context.getExternalContext();
+
+        if (context.getPartialViewContext().isPartialRequest())
+        {
+            // try to get (or create) a ResponseSwitch and turn off the output
+            Object origResponse = context.getExternalContext().getResponse();
+            ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(origResponse);
+            if (responseSwitch == null)
+            {
+                // no ResponseSwitch installed yet - create one 
+                responseSwitch = ExternalContextUtils.createResponseSwitch(origResponse);
+                if (responseSwitch != null)
+                {
+                    // install the ResponseSwitch
+                    context.getExternalContext().setResponse(responseSwitch);
+                }
+            }
+            if (responseSwitch != null)
+            {
+                responseSwitch.setEnabled(context, false);
+            }
+        }
+        
         ServletResponse response = (ServletResponse) externalContext.getResponse();
         ServletRequest request = (ServletRequest) externalContext.getRequest();
         
@@ -88,8 +112,13 @@ public class JspViewDeclarationLanguage 
             return;
         }
 
-        // store the wrapped response in the request, so it is thread-safe
-        setAfterViewTagResponseWrapper(externalContext, wrappedResponse);
+        //Skip this step if we are rendering an ajax request, because no content outside
+        //f:view tag should be output.
+        if (!context.getPartialViewContext().isPartialRequest())
+        {
+            // store the wrapped response in the request, so it is thread-safe
+            setAfterViewTagResponseWrapper(externalContext, wrappedResponse);
+        }
     }
 
     @Override