You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2007/03/23 12:04:27 UTC

svn commit: r521670 - in /myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces: application/jsp/ViewResponseWrapper.java taglib/core/SubviewTag.java

Author: matzew
Date: Fri Mar 23 04:04:26 2007
New Revision: 521670

URL: http://svn.apache.org/viewvc?view=rev&rev=521670
Log:
MYFACES-1458 thx to Martin Heimberger for providing this fix

Modified:
    myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java
    myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/SubviewTag.java

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java?view=diff&rev=521670&r1=521669&r2=521670
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java Fri Mar 23 04:04:26 2007
@@ -73,10 +73,23 @@
         }
         return _writer;
     }
+    
+    public void reset()
+    {
+        if (_charArrayWriter != null)
+        {
+            _charArrayWriter.reset();
+        }
+    }
 
     @Override
     public String toString()
     {
-        return _charArrayWriter.toString();
+        if (_charArrayWriter != null)
+        {
+            return _charArrayWriter.toString();
+        }
+        return null;
     }
-}
+
+}
\ No newline at end of file

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/SubviewTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/SubviewTag.java?view=diff&rev=521670&r1=521669&r2=521670
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/SubviewTag.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/taglib/core/SubviewTag.java Fri Mar 23 04:04:26 2007
@@ -15,16 +15,24 @@
  */
 package org.apache.myfaces.taglib.core;
 
-import javax.faces.webapp.UIComponentTag;
+import javax.faces.webapp.UIComponentELTag;
+import javax.faces.component.UIComponent;
 import javax.faces.component.UINamingContainer;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.application.jsp.ViewResponseWrapper;
 
 /**
  * @author Thomas Spiegl (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-public class SubviewTag
-    extends UIComponentTag //UIComponentELTag
+public class SubviewTag extends UIComponentELTag
 {
+    public SubviewTag() {
+        super();
+    }
+    
     public String getComponentType()
     {
         return UINamingContainer.COMPONENT_TYPE;
@@ -34,4 +42,47 @@
     {
         return null;
     }
+    
+    /**
+     * Creates a UIComponent from the BodyContent
+     * If a Subview is included via the <jsp:include> tag
+     * the corresponding jsp is rendered with
+     * getServletContext().getRequestDispatcher("includedSite").include(request,response)
+     * and it is possible that something was written to the Response direct.
+     * So is is necessary that the content of the wrapped response is added to the componenttree.
+     * @return UIComponent or null
+     */
+    protected UIComponent createVerbatimComponentFromBodyContent() {
+        UIOutput component = (UIOutput) super.createVerbatimComponentFromBodyContent();
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        Object response = facesContext.getExternalContext().getResponse();
+        String wrappedOutput;
+
+        if (response instanceof ViewResponseWrapper)
+        {
+            ViewResponseWrapper wrappedResponse = (ViewResponseWrapper) response;
+            wrappedOutput = wrappedResponse.toString();
+            if (wrappedOutput.length() > 0)
+            {
+                String componentvalue = null;
+                if (component != null)
+                {
+                    //save the Value of the Bodycontent
+                  componentvalue = (String) component.getValue();
+                }
+                component = super.createVerbatimComponent();
+                if (componentvalue != null)
+                {
+                    component.setValue(wrappedOutput + componentvalue);
+                }
+                else
+                {
+                    component.setValue(wrappedOutput);
+                }
+                wrappedResponse.reset();
+            }
+        }
+        return component;
+    }    
+    
 }