You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ms...@apache.org on 2010/03/31 21:34:42 UTC

svn commit: r929680 - /myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js

Author: mstarets
Date: Wed Mar 31 19:34:41 2010
New Revision: 929680

URL: http://svn.apache.org/viewvc?rev=929680&view=rev
Log:
Handle ViewState upadte specially during the processing of legacy PPR response

Modified:
    myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js

Modified: myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js?rev=929680&r1=929679&r2=929680&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js Wed Mar 31 19:34:41 2010
@@ -27,6 +27,8 @@ function TrPage()
   }
 }
 
+TrPage._VIEW_STATE_ID = "javax.faces.ViewState";
+
 /**
  * Get the shared instance of the page object.
  */
@@ -253,7 +255,7 @@ TrPage.prototype._handlePprResponse = fu
             switch (TrPage._getNodeName(changeNode))
             {
               case "update":
-                this._handlePprResponseFragment(changeNode);
+                this._handlePprResponseFragment(changeNode, requestEvent.getFormId());
                 break;
 
               case "eval":
@@ -422,9 +424,21 @@ TrPage.prototype.__handlePprResponseActi
 }
 
 // Handles a single fragment node in a ppr response.
-TrPage.prototype._handlePprResponseFragment = function (fragmentNode)
+TrPage.prototype._handlePprResponseFragment = function (fragmentNode, formId)
 {
   var doc = window.document;
+  
+  if (fragmentNode.getAttribute("id") == TrPage._VIEW_STATE_ID)
+  {
+    // JSF2 short-circuits writeState() during partial requets. The state
+    // is always written out as a special "update" element
+    // Perform special handling for the javax.faces.ViewState Id here just
+    // like jsf.ajax.request() does
+    this._updateViewState(doc, fragmentNode, formId);
+    
+    return;
+  }
+  
   var targetNode;
   var activeNode;
   var refocusId = null;
@@ -461,7 +475,7 @@ TrPage.prototype._handlePprResponseFragm
 
     var sourceNode = TrPage._getFirstElementWithId(tempDiv);
 
-    var targetNode = _getElementById(doc, sourceNode.id);
+    targetNode = _getElementById(doc, sourceNode.id);
     if (!targetNode)
     {
       return;
@@ -509,7 +523,7 @@ TrPage.prototype._handlePprResponseFragm
       return;
 
     // Find the target node
-    targetNode = _getElementById(doc, id);
+    targetNode = _getElementById(doc, id);   
     activeNode = _getActiveElement();
     if (activeNode && TrPage._isDomAncestorOf(activeNode, targetNode))
       refocusId = activeNode.id;
@@ -544,6 +558,32 @@ TrPage.prototype._handlePprResponseFragm
   }
 }
 
+TrPage.prototype._updateViewState = function(doc, sourceNode, formId)
+{  
+  var form  = null;
+  
+  if (formId)
+    form = doc.getElementById(formId);
+  
+  if (!form)
+    form = doc.forms[0];
+  
+  if (!form)
+    return;
+  
+  var input = form[TrPage._VIEW_STATE_ID];
+  
+  if (!input)
+  {
+    input = doc.createElement("input");
+    input.type = 'hidden';
+    input.name = TrPage._VIEW_STATE_ID;
+    form.appendChild(input);
+  }
+  
+  input.value = TrPage._getTextContent(sourceNode);
+}
+
 /**
  * Return true if "parent" is an ancestor of (or equal to) "child"
  */
@@ -959,7 +999,7 @@ TrPage.prototype._getDomToBeUpdated = fu
     }
 
     var id = node.getAttribute("id");
-    if (id == "javax.faces.ViewState")
+    if (id == TrPage._VIEW_STATE_ID)
     {
       continue;
     }