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 2013/08/16 01:27:12 UTC

svn commit: r1514539 - in /myfaces/core/trunk: api/src/main/java/javax/faces/context/ impl/src/main/java/org/apache/myfaces/context/servlet/ impl/src/main/java/org/apache/myfaces/renderkit/html/

Author: lu4242
Date: Thu Aug 15 23:27:11 2013
New Revision: 1514539

URL: http://svn.apache.org/r1514539
Log:
MYFACES-3754 Update PartialViewContext and PartialResponseWriter to new spec 

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/context/PartialResponseWriter.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.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/renderkit/html/HtmlResponseStateManager.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/context/PartialResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/context/PartialResponseWriter.java?rev=1514539&r1=1514538&r2=1514539&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/context/PartialResponseWriter.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/context/PartialResponseWriter.java Thu Aug 15 23:27:11 2013
@@ -143,7 +143,9 @@ public class PartialResponseWriter exten
     @Override
     public void startDocument() throws IOException
     {
-        _wrapped.write ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
+        // JSF 2.2 section 2.2.6.1 Render Response Partial Processing
+        // use writePreamble(...)
+        //_wrapped.write ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
         
         _wrapped.startElement ("partial-response", null);
         

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java?rev=1514539&r1=1514538&r2=1514539&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java Thu Aug 15 23:27:11 2013
@@ -30,6 +30,7 @@ import javax.el.ELContextListener;
 import javax.faces.FactoryFinder;
 import javax.faces.application.Application;
 import javax.faces.application.ApplicationFactory;
+import javax.faces.component.UINamingContainer;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExceptionHandler;
 import javax.faces.context.ExternalContext;
@@ -69,6 +70,7 @@ public abstract class FacesContextImplBa
     private ApplicationFactory _applicationFactory = null;
     
     private List<String> _resourceLibraryContracts;
+    private Character _separatorChar;
 
     /**
      * Base constructor.
@@ -124,6 +126,7 @@ public abstract class FacesContextImplBa
         _exceptionHandler = null;
         _cachedRenderKit = null;
         _cachedRenderKitId = null;
+        _separatorChar = null;
         
         // Spec JSF 2 section getAttributes when release is called the attributes map
         // must!!! be cleared! (probably to trigger some clearance methods on possible
@@ -347,6 +350,16 @@ public abstract class FacesContextImplBa
             _resourceLibraryContracts = new ArrayList<String>(contracts);
         }
     }
+
+    @Override
+    public char getNamingContainerSeparatorChar()
+    {
+        if (_separatorChar == null)
+        {
+            _separatorChar = UINamingContainer.getSeparatorChar(this);
+        }
+        return _separatorChar;
+    }
     
     /**
      * has to be thrown in many of the methods if the method is called after the instance has been released!

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=1514539&r1=1514538&r2=1514539&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 Thu Aug 15 23:27:11 2013
@@ -45,12 +45,14 @@ import javax.faces.context.PartialRespon
 import javax.faces.context.PartialViewContext;
 import javax.faces.context.ResponseWriter;
 import javax.faces.event.PhaseId;
+import javax.faces.lifecycle.ClientWindow;
 import javax.faces.render.RenderKit;
 import javax.faces.render.RenderKitFactory;
 import javax.faces.view.ViewMetadata;
 
 import org.apache.myfaces.context.PartialResponseWriterImpl;
 import org.apache.myfaces.context.RequestViewContext;
+import org.apache.myfaces.renderkit.html.HtmlResponseStateManager;
 import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.apache.myfaces.shared.util.ExternalContextUtils;
 import org.apache.myfaces.shared.util.StringUtils;
@@ -462,9 +464,17 @@ public class PartialViewContextImpl exte
 
         try
         {
+            String currentEncoding = writer.getCharacterEncoding();
+            writer.writePreamble("<?xml version=\"1.0\" encoding=\""+
+                (currentEncoding == null ? "UTF-8" : currentEncoding) +"\"?>");
             writer.startDocument();
             inDocument = true;
             _facesContext.setResponseWriter(writer);
+            
+            if (isResetValues())
+            {
+                viewRoot.resetValues(_facesContext, getRenderIds());
+            }
 
             if (pvc.isRenderAll())
             {
@@ -570,10 +580,21 @@ public class PartialViewContextImpl exte
             String viewState = _facesContext.getApplication().getStateManager().getViewState(_facesContext);
             if (viewState != null)
             {
-                writer.startUpdate(PartialResponseWriter.VIEW_STATE_MARKER);
+                writer.startUpdate(HtmlResponseStateManager.generateUpdateViewStateId(
+                    _facesContext));
                 writer.write(viewState);
                 writer.endUpdate();
             }
+            
+            
+            ClientWindow cw = _facesContext.getExternalContext().getClientWindow();
+            if (cw != null)
+            {
+                writer.startUpdate(HtmlResponseStateManager.generateUpdateClientWindowId(
+                    _facesContext));
+                writer.write(cw.getId());
+                writer.endUpdate();
+            }
         }
         catch (IOException ex)
         {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java?rev=1514539&r1=1514538&r2=1514539&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java Thu Aug 15 23:27:11 2013
@@ -19,10 +19,8 @@
 package org.apache.myfaces.renderkit.html;
 
 import java.io.IOException;
-import java.util.concurrent.atomic.AtomicLong;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import javax.faces.component.UINamingContainer;
 
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
@@ -56,6 +54,9 @@ public class HtmlResponseStateManager ex
 
     public static final String STANDARD_STATE_SAVING_PARAM = "javax.faces.ViewState";
     
+    private static final String VIEW_STATE_COUNTER = "oam.partial.VIEW_STATE_COUNTER";
+    private static final String CLIENT_WINDOW_COUNTER = "oam.partial.CLIENT_WINDOW_COUNTER";
+
     /**
      * Define if the state caching code should be handled by the ResponseStateManager or by the StateManager used.
      * <p>
@@ -74,8 +75,6 @@ public class HtmlResponseStateManager ex
     
     private StateCacheFactory _stateCacheFactory;
     
-    private AtomicLong _counter = new AtomicLong();
-    
     public HtmlResponseStateManager()
     {
         _stateCacheFactory = new StateCacheFactoryImpl();
@@ -153,16 +152,7 @@ public class HtmlResponseStateManager ex
         {
             responseWriter.startElement(HTML.INPUT_ELEM, null);
             responseWriter.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
-            StringBuilder sb = new StringBuilder();
-            char sepChar = UINamingContainer.getSeparatorChar(facesContext);
-            sb.append(facesContext.getViewRoot().getContainerClientId(facesContext));
-            sb.append(sepChar);
-            sb.append(ResponseStateManager.CLIENT_WINDOW_PARAM);
-            sb.append(sepChar);
-            // A counter is enough, because only uniqueness of UIViewRoot 
-            // per page is needed
-            sb.append(_counter.incrementAndGet());
-            responseWriter.writeAttribute(HTML.ID_ATTR, sb.toString(), null);
+            responseWriter.writeAttribute(HTML.ID_ATTR, generateUpdateClientWindowId(facesContext), null);
             responseWriter.writeAttribute(HTML.NAME_ATTR, ResponseStateManager.CLIENT_WINDOW_PARAM, null);
             responseWriter.writeAttribute(HTML.VALUE_ATTR, clientWindow.getId(), null);
             responseWriter.endElement(HTML.INPUT_ELEM);
@@ -375,4 +365,60 @@ public class HtmlResponseStateManager ex
         return _stateCacheFactory.getStateCache(facesContext);
     }
 
+    public static String generateUpdateClientWindowId(FacesContext facesContext)
+    {
+        // JSF 2.2 section 2.2.6.1 Partial State Rendering
+        // According to the javascript doc of jsf.ajax.response,
+        //
+        // The new syntax looks like this:
+        // <update id="<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>javax.faces.ClientWindow<SEP><UNIQUE_PER_VIEW_NUMBER>">
+        //    <![CDATA[...]]>
+        // </update>
+        //
+        // UNIQUE_PER_VIEW_NUMBER aim for portlet case. In that case it is possible to have
+        // multiple sections for update. In servlet case there is only one update section per
+        // ajax request.
+        
+        String id;
+        char separator = facesContext.getNamingContainerSeparatorChar();
+        Integer count = (Integer) facesContext.getAttributes().get(CLIENT_WINDOW_COUNTER);
+        if (count == null)
+        {
+            count = Integer.valueOf(0);
+        }
+        count += 1;
+        id = facesContext.getViewRoot().getContainerClientId(facesContext) + 
+            separator + ResponseStateManager.CLIENT_WINDOW_PARAM + separator + count;
+        facesContext.getAttributes().put(CLIENT_WINDOW_COUNTER, count);
+        return id;
+    }
+    
+    public static String generateUpdateViewStateId(FacesContext facesContext)
+    {
+        // JSF 2.2 section 2.2.6.1 Partial State Rendering
+        // According to the javascript doc of jsf.ajax.response,
+        //
+        // The new syntax looks like this:
+        // <update id="<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>javax.faces.ViewState<SEP><UNIQUE_PER_VIEW_NUMBER>">
+        //    <![CDATA[...]]>
+        // </update>
+        //
+        // UNIQUE_PER_VIEW_NUMBER aim for portlet case. In that case it is possible to have
+        // multiple sections for update. In servlet case there is only one update section per
+        // ajax request.
+        
+        String id;
+        char separator = facesContext.getNamingContainerSeparatorChar();
+        Integer count = (Integer) facesContext.getAttributes().get(VIEW_STATE_COUNTER);
+        if (count == null)
+        {
+            count = Integer.valueOf(0);
+        }
+        count += 1;
+        id = facesContext.getViewRoot().getContainerClientId(facesContext) + 
+            separator + ResponseStateManager.VIEW_STATE_PARAM + separator + count;
+        facesContext.getAttributes().put(VIEW_STATE_COUNTER, count);
+        return id;
+    }
+
 }