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 2009/10/02 03:30:36 UTC

svn commit: r820861 - in /myfaces/core/trunk: api/src/main/java/javax/faces/application/StateManager.java api/src/main/java/javax/faces/render/ResponseStateManager.java impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java

Author: lu4242
Date: Fri Oct  2 01:30:36 2009
New Revision: 820861

URL: http://svn.apache.org/viewvc?rev=820861&view=rev
Log:
MYFACES-2014 Implement ResponseStateManager.getViewState(FacesContext, Object)

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/application/StateManager.java
    myfaces/core/trunk/api/src/main/java/javax/faces/render/ResponseStateManager.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/application/StateManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/application/StateManager.java?rev=820861&r1=820860&r2=820861&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/application/StateManager.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/application/StateManager.java Fri Oct  2 01:30:36 2009
@@ -182,16 +182,13 @@
     }
     
     /**
-     * Convenience method to return the view state as a String with no RenderKit specific markup. This default 
-     * implementation of this method will call {@link #saveView(javax.faces.context.FacesContext)} and passing the 
-     * result to and returning the resulting value from 
-     * ResponseStateManager.getViewState(javax.faces.context.FacesContext, Object). 
-     * 
-     * @param context {@link FacesContext} for the current request
-     * 
-     * @return the view state as a String with no RenderKit specific markup.
+     * TODO: This method should be called from somewhere when ajax response is created to update the state saving param
+     * on client. The place where this method is called is an implementation detail, so there is no references about
+     * from where in the spec javadoc. 
      * 
      * @since 2.0
+     * @param context
+     * @return
      */
     public String getViewState(FacesContext context)
     {

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/render/ResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/render/ResponseStateManager.java?rev=820861&r1=820860&r2=820861&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/render/ResponseStateManager.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/render/ResponseStateManager.java Fri Oct  2 01:30:36 2009
@@ -78,15 +78,11 @@
     }
     
     /**
-     * Return the specified state as a String without any markup related to the rendering technology supported by 
-     * this ResponseStateManager.
-     * 
-     * @param context the {@link FacesContext} for the current request
-     * @param state the state from which the String version will be generated from
-     * 
-     * @return the view state for this request without any markup specifics
      * 
      * @since 2.0
+     * @param context
+     * @param state
+     * @return
      */
     public String getViewState(FacesContext context, Object state)
     {

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=820861&r1=820860&r2=820861&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 Fri Oct  2 01:30:36 2009
@@ -27,7 +27,9 @@
 import org.apache.myfaces.shared_impl.renderkit.html.util.JavascriptUtils;
 import org.apache.myfaces.shared_impl.util.StateUtils;
 
+import javax.faces.FacesException;
 import javax.faces.application.StateManager;
+import javax.faces.application.StateManager.SerializedView;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -234,4 +236,70 @@
     {
         return context.getExternalContext().getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
     }
+
+    @Override
+    public String getViewState(FacesContext facesContext, Object state)
+    {
+        if (state == null)
+        {
+            return null;
+        }
+        
+        Object treeStruct = null;
+        Object compStates = null;
+        
+        if (state instanceof SerializedView)
+        {
+            SerializedView view = (SerializedView)state; 
+            treeStruct = view.getStructure();
+            compStates = view.getState();
+        }
+        else if (state instanceof Object[])
+        {
+            Object[] structureAndState = (Object[])state;
+
+            if (structureAndState.length == 2)
+            {
+                treeStruct = structureAndState[0];
+                compStates = structureAndState[1];
+            }
+            else
+            {
+                throw new FacesException("The state should be an array of Object[] of lenght 2");
+            }
+        }
+        else
+        {
+            throw new FacesException("The state should be an array of Object[] of lenght 2, or a SerializedView instance");
+        }
+        
+        Object[] savedState = new Object[3];
+
+        if (facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext))
+        {
+            if (treeStruct != null)
+            {
+                savedState[TREE_PARAM] = treeStruct;
+            }
+
+            if (compStates != null)
+            {
+                savedState[STATE_PARAM] = compStates;
+            }
+        }
+        else
+        {
+            // write viewSequence
+            if (treeStruct != null)
+            {
+                if (treeStruct instanceof String)
+                {
+                    savedState[TREE_PARAM] = treeStruct;
+                }
+            }
+        }
+        savedState[VIEWID_PARAM] = facesContext.getViewRoot().getViewId();
+
+        return StateUtils.construct(savedState, facesContext.getExternalContext());
+    }
 }