You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/03/22 22:58:18 UTC

svn commit: r926369 - in /myfaces/trinidad/branches/jsf2_ajax: ./ trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ trinidad-examples/trinidad-demo/src/main/webapp/components/ trinidad-examples/trinidad-demo/src/main/webapp...

Author: arobinson74
Date: Mon Mar 22 21:58:18 2010
New Revision: 926369

URL: http://svn.apache.org/viewvc?rev=926369&view=rev
Log:
Checkpoint

Modified:
    myfaces/trinidad/branches/jsf2_ajax/   (props changed)
    myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoStatusBean.java
    myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java
    myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/components/inputFile.jspx
    myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
    myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
    myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js
    myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
    myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js

Propchange: myfaces/trinidad/branches/jsf2_ajax/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Mar 22 21:58:18 2010
@@ -4,5 +4,6 @@
 /myfaces/trinidad/branches/TRINIDAD-1402:745675
 /myfaces/trinidad/branches/ar_clientBehaviors:881469-891464
 /myfaces/trinidad/branches/jwaldman_StyleMap:754977-770778
+/myfaces/trinidad/branches/trinidad-1.2.x:923447,923460
 /myfaces/trinidad/branches/trinidad-2.0.x:823098-895949
 /myfaces/trinidad/trunk:819601,819622,834147,886881,888973,893043

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoStatusBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoStatusBean.java?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoStatusBean.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoStatusBean.java Mon Mar 22 21:58:18 2010
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -22,6 +22,9 @@ import java.text.SimpleDateFormat;
 
 import java.util.Date;
 
+import org.apache.myfaces.trinidad.model.UploadedFile;
+
+
 public class PartialDemoStatusBean implements java.io.Serializable
 {
   public PartialDemoStatusBean()
@@ -144,6 +147,24 @@ public class PartialDemoStatusBean imple
     _checkBoxUpdateCount++;
   }
 
+  public String getUploadFileState()
+  {
+    return this._uploadFileState;
+  }
+
+  public void setUploadFile(UploadedFile file)
+  {
+    if (file == null)
+    {
+      this._uploadFileState = _DEFAULT_UPLOAD_FILE;
+    }
+    else
+    {
+      this._uploadFileState = String.format(
+        "Uploaded file %s (%d bytes)", file.getFilename(), file.getLength());
+    }
+  }
+
   public void reset()
   {
     resetCheckBox();
@@ -151,6 +172,7 @@ public class PartialDemoStatusBean imple
     _linkUpdate = _DEFAULT_LINK_UPDATE;
     _radioState = _DEFAULT_RADIO_STATE;
     _textValue = _DEFAULT_TEXT_VALUE;
+    _uploadFileState = _DEFAULT_UPLOAD_FILE;
   }
 
   private int     _checkBoxUpdateCount;
@@ -160,6 +182,7 @@ public class PartialDemoStatusBean imple
   private String  _linkUpdate;
   private String  _radioState;
   private String  _textValue;
+  private String  _uploadFileState;
 
   private static String _NOTHING              = "nothing yet.";
   private static String _DEFAULT_CHECK_STATE  = "updates this text.";
@@ -170,4 +193,5 @@ public class PartialDemoStatusBean imple
   private static String _DEFAULT_RADIO_STATE  = "no selection yet.";
   private static String _DEFAULT_TEXT_STATE   = _NOTHING;
   private static String _DEFAULT_TEXT_VALUE   = "Change this text";
+  private static String _DEFAULT_UPLOAD_FILE  = "No file was uploaded";
 }

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/PartialDemoUtilBean.java Mon Mar 22 21:58:18 2010
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -27,6 +27,8 @@ import javax.faces.event.ValueChangeEven
 
 import org.apache.myfaces.trinidad.component.UIXOutput;
 import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.model.UploadedFile;
+
 
 public class PartialDemoUtilBean
 {
@@ -114,13 +116,38 @@ public class PartialDemoUtilBean
     Object newValue = vce.getNewValue();
     if ((newValue != null) && !"".equals(newValue))
     {
-      FacesContext fContext = FacesContext.getCurrentInstance(); 
-      ViewHandler vh = fContext.getApplication().getViewHandler(); 
-      UIViewRoot root = vh.createView(fContext, newValue.toString()); 
-      fContext.setViewRoot(root); 
+      FacesContext fContext = FacesContext.getCurrentInstance();
+      ViewHandler vh = fContext.getApplication().getViewHandler();
+      UIViewRoot root = vh.createView(fContext, newValue.toString());
+      fContext.setViewRoot(root);
     }
   }
 
+  public void setRenderInputFile(boolean renderInputFile)
+  {
+    this._renderInputFileTemp = renderInputFile;
+  }
+
+  public boolean isRenderInputFile()
+  {
+    Boolean value = (Boolean)
+      FacesContext.getCurrentInstance().getViewRoot().getViewMap().get(
+        _RENDER_INPUT_FILE_KEY);
+    return value != null && value;
+  }
+
+  public void fileUploaded(ValueChangeEvent event)
+  {
+    _status.setUploadFile((UploadedFile) event.getNewValue());
+  }
+
+  public void updateRenderInputFileState(ActionEvent event)
+  {
+    FacesContext.getCurrentInstance().getViewRoot().getViewMap().put(
+      _RENDER_INPUT_FILE_KEY, _renderInputFileTemp);
+    _renderInputFileTemp = null;
+  }
+
   private void _resetList()
   {
     _listUpdate.setValue("nothing yet.");
@@ -135,4 +162,7 @@ public class PartialDemoUtilBean
 
   private PartialDemoStatusBean _status;
   private UIXOutput _listUpdate;
+  private Boolean _renderInputFileTemp;
+  private final static String _RENDER_INPUT_FILE_KEY = PartialDemoUtilBean.class.getName() +
+                                                       ".renderInputFile";
 }

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/components/inputFile.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/components/inputFile.jspx?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/components/inputFile.jspx (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/components/inputFile.jspx Mon Mar 22 21:58:18 2010
@@ -30,7 +30,7 @@
           <f:facet name="separator">
             <tr:separator/>
           </f:facet>
-          <tr:panelGroupLayout layout="horizontal">
+          <tr:panelGroupLayout layout="horizontal" partialTriggers="cb1">
             <tr:commandLink immediate="true" text="Component Guide" action="guide"/>
             <tr:spacer width="10"/>
             <tr:goLink destination="http://myfaces.apache.org/trinidad/trinidad-api/tagdoc/tr_inputFile.html"
@@ -39,7 +39,7 @@
           <tr:outputFormatted styleUsage="instruction" value="&lt;b>inputFile&lt;/b>"/>
           <tr:inputFile binding="#{editor.component}" label="Label"
                         valueChangeListener="#{ui.fileUploaded}"/>
-          <tr:commandButton text="Submit"/>
+          <tr:commandButton text="Submit" id="cb1" partialSubmit="true" />
           <jsp:directive.include file="editor.jspf"/>
         </tr:panelGroupLayout>
       </tr:form>

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml Mon Mar 22 21:58:18 2010
@@ -69,7 +69,7 @@ function setFocus(event)
         </trh:script>
       </tr:group>
     </f:facet>
-    <tr:form>
+    <tr:form usesUpload="#{partialDemoUtil.renderInputFile}" partialTriggers="ifsbc1">
       <tr:panelPage>
         <f:facet name="navigationGlobal">
           <tr:panelGroupLayout id="pgl1" layout="horizontal">
@@ -230,6 +230,31 @@ function setFocus(event)
                 <tr:statusIndicator id="si5" />
               </tr:panelGroupLayout>
             </tr:panelHeader>
+            <tr:panelHeader text="Input File / Multi-part form demonstration">
+              <tr:outputFormatted styleUsage="instruction"
+                                  value="This section will add a input file to the page so that a multi-part submission is made which will bypass the JSF 2 AJAX and fall back on Trinidad PPR code." />
+              <tr:panelGroupLayout id="ifpgl1" layout="horizontal">
+                <f:facet name="separator">
+                  <tr:spacer width="10" id="ifsp1"/>
+                </f:facet>
+                <tr:selectBooleanCheckbox id="ifsbc1" value="#{partialDemoUtil.renderInputFile}" />
+                <tr:commandButton id="ifcb1" text="Update the visibile status"
+                                  partialSubmit="true"
+                                  actionListener="#{partialDemoUtil.updateRenderInputFileState}" />
+                <tr:statusIndicator id="ifsi1" />
+              </tr:panelGroupLayout>
+
+              <tr:panelGroupLayout id="ifpgl2" layout="horizontal"
+                                   rendered="#{partialDemoUtil.renderInputFile}">
+                <tr:inputFile id="ifif1" valueChangeListener="#{partialDemoUtil.fileUploaded}"
+                              label="inputFile" />
+                <tr:commandButton id="ifcb2" text="Submit the file"
+                                  partialSubmit="true" />
+                <tr:outputFormatted id="ifof1" styleUsage="instruction"
+                                    value="#{partialDemoUtil.status.uploadFileState}"
+                                    partialTriggers="ifcb2" />
+              </tr:panelGroupLayout>
+            </tr:panelHeader>
           </tr:panelGroupLayout>
           <tr:panelLabelAndMessage id="plam1" label="Ajax Status Log">
             <tr:inputText id="it1" value="" simple="true" rows="7" columns="100" />

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js Mon Mar 22 21:58:18 2010
@@ -18,13 +18,13 @@
  */
 function TrPage()
 {
-  if (typeof jsf != "undefined")
+  this._loadedLibraries = TrPage._collectLoadedLibraries();
+  this._requestQueue = new TrRequestQueue(window);
+
+  if (this._requestQueue.__useJsfBuiltInAjaxForXhr())
   {
     jsf.ajax.addOnEvent(TrUIUtils.createCallback(this, this._jsfAjaxCallback));
   }
-
-  this._loadedLibraries = TrPage._collectLoadedLibraries();
-  this._requestQueue = new TrRequestQueue(window);
 }
 
 /**
@@ -38,6 +38,38 @@ TrPage.getInstance = function()
   return TrPage._INSTANCE;
 }
 
+TrPage._MockXHR = function(requestEvent)
+{
+  this.UNSENT = 0;
+  this.OPENED = 1;
+  this.HEADERS_RECEIVED = 2;
+  this.LOADING = 3;
+  this.DONE = 4;
+  this.readyState = this.DONE;
+  this.status = requestEvent.getResponseStatusCode();
+  this.statusText = "";
+  this._requestEvent = requestEvent;
+  this.responseText = requestEvent.getResponseText();
+  this.responseXML = requestEvent.getResponseXML();
+}
+
+// Unsupported API methods that require a return value:
+TrPage._MockXHR.prototype.getResponseHeader = function(header)
+{
+  return this._requestEvent.getResponseHeader(header);
+}
+
+TrPage._MockXHR.prototype.getAllResponseHeaders = function()
+{
+  return this._requestEvent._getAllResponseHeaders();
+}
+
+// No-op API methods:
+TrPage._MockXHR.prototype.open =
+TrPage._MockXHR.prototype.setRequestHeader =
+TrPage._MockXHR.prototype.send =
+TrPage._MockXHR.prototype.abort = function () {};
+
 /**
  * Return the shared request queue for the page.
  */
@@ -97,7 +129,7 @@ TrPage.prototype._requestStatusChanged =
           }
           else
           {
-            this._handlePprResponse(responseDocument.documentElement);
+            this._handlePprResponse(requestEvent, responseDocument);
           }
         }
       }
@@ -169,11 +201,50 @@ TrPage.prototype._handleJsfAjaxResponse 
   }
 }
 
-TrPage.prototype._handlePprResponse = function(documentElement)
+/**
+ * Method to bridge compatibility between the Trinidad IFrame-PPR implementation
+ * an the JSF 2 AJAX javascript API
+ */
+TrPage.prototype._delegateResponseToJsfAjax = function(requestEvent, document)
 {
-  var rootNodeName = TrPage._getNodeName(documentElement);
+console.log("_delegateResponseToJsfAjax");
+  // We wish to have JSF 2 handle the response. In order to do that we need to
+  // construct the necessary parameters for the jsf.ajax.response method.
+  //
+  // The first parameter is the XHR object, so we must wrap the response in such
+  // a way that JSF 2 believes the data to be coming from an XHR object
+  //
+  var request = new TrPage._MockXHR(requestEvent);
+
+  // The second parameter is the context object which is the request context object
+  // containing the source element, onerror callback, and onevent callback.
+  var source = requestEvent.getSource();
+  if (source)
+  {
+    source = document.getElementById(source);
+  }
+  var context =
+  {
+    "onevent": null,
+    "onerror": null,
+    "source": source,
+    "formid": requestEvent.getFormId(),
+    "render": null
+  };
 
-  if (rootNodeName == "content")
+  jsf.ajax.response(request, context);
+}
+
+TrPage.prototype._handlePprResponse = function(requestEvent, document)
+{
+  if (this._requestQueue.__useJsfBuiltInAjaxForXhr())
+  {
+    return this._delegateResponseToJsfAjax(requestEvent, document);
+  }
+console.log("_handlePprResponse");
+  var documentElement = document.documentElement;
+  var rootNodeName = TrPage._getNodeName(documentElement);
+  if (rootNodeName == "partial-response")
   {
     // Update the form action
     this._handlePprResponseAction(documentElement);
@@ -184,41 +255,52 @@ TrPage.prototype._handlePprResponse = fu
     for (var i = 0; i < length; i++)
     {
       var childNode = childNodes[i];
-      var childNodeName = TrPage._getNodeName(childNode);
 
-      if (childNodeName == "fragment")
-      {
-        this._handlePprResponseFragment(childNode);
-      }
-      else if (childNodeName == "script")
-      {
-        this._handlePprResponseScript(childNode);
-      }
-      else if (childNodeName == "script-library")
+      switch (TrPage._getNodeName(childNode))
       {
-        this._handlePprResponseLibrary(childNode);
+        case "changes":
+          for (var j = 0, size = childNode.childNodes.length; j < size; ++j)
+          {
+            var changeNode = childNode.childNodes[j];
+            switch (TrPage._getNodeName(changeNode))
+            {
+              case "update":
+                this._handlePprResponseFragment(changeNode);
+                break;
+
+              case "eval":
+                this._handlePprResponseScript(changeNode);
+                break;
+
+              case "extension":
+                for (var k = 0, extsize = changeNode.childNodes.length; k < extsize; ++k)
+                {
+                  if (changeNode.childNodes[k].nodeName == "script-library")
+                  {
+                    this._handlePprResponseLibrary(changeNode.childNodes[k]);
+                  }
+                }
+                break;
+
+              // Do not support the new updates with the Trinidad legacy fallback code:
+              default: break;
+            }
+          }
+          break;
+        case "error":
+          var nodeText = TrPage._getTextContent(childNode.nextSibling.firstChild);
+          // This should not happen - there should always be an error message
+          if (nodeText == null)
+            nodeText = "Unknown error during PPR";
+          alert(nodeText);
+          return;
+        case "redirect":
+          var url = TrPage._getTextContent(childNode);
+          // TODO: fix for portlets???
+          window.location.href = url;
       }
     }
   }
-  else if (rootNodeName == "redirect")
-  {
-    var url = TrPage._getTextContent(documentElement);
-    // TODO: fix for portlets???
-    window.location.href = url;
-  }
-  else if (rootNodeName == "error")
-  {
-    var nodeText = TrPage._getTextContent(documentElement);
-    // This should not happen - there should always be an error
-    // message
-    if (nodeText == null)
-      nodeText = "Unknown error during PPR";
-    alert(nodeText);
-  }
-  else if (rootNodeName == "noop")
-  {
-    // No op
-  }
   else
   {
     // FIXME: log an error
@@ -380,7 +462,11 @@ TrPage.prototype._handlePprResponseFragm
     if (!firstFragmenChildNode)
        return;
 
-    var outerHTML = firstFragmenChildNode.data;
+    var outerHTML = "";
+    for (var i = 0, size = fragmentNode.childNodes.length; i < size; ++i)
+    {
+      outerHTML += fragmentNode.childNodes[i].data;
+    }
 
     // Windows Mobile 6 requires the element to be a child of
     // document.body to allow setting its innerHTML property.
@@ -519,15 +605,17 @@ TrPage.prototype._getFirstElementFromFra
 {
   // Fragment nodes contain a single CDATA section
   var fragmentChildNodes = fragmentNode.childNodes;
-  // assert((fragmentChildNodes.length == 1), "invalid fragment child count");
 
-  var cdataNode = fragmentNode.childNodes[0];
-  // assert((cdataNode.nodeType == 4), "invalid fragment content");
-  // assert(cdataNode.data, "null fragment content");
-
-  // The new HTML content is in the CDATA section.
-  // TODO: Is CDATA content ever split across multiple nodes?
-  var outerHTML = cdataNode.data;
+  // assert((fragmentChildNodes.length == 0), "invalid fragment child count");
+  var outerHTML = "";
+  for (var i = 0, size = fragmentChildNodes.length; i < size; ++i)
+  {
+    // The new HTML content is in the CDATA section.
+    if (fragmentChildNodes[i].nodeType == 4)
+    {
+      outerHTML += fragmentChildNodes[i].data;
+    }
+  }
 
   // We get our html node by slamming the fragment contents into a div.
   var doc = window.document;
@@ -537,14 +625,12 @@ TrPage.prototype._getFirstElementFromFra
   div.innerHTML = outerHTML;
 
   return TrPage._getFirstElementWithId(div);
-
 }
 
 // Returns the first element underneath the specified dom node
 // which has an id.
 TrPage._getFirstElementWithId = function(domNode)
 {
-
   var childNodes = domNode.childNodes;
   var length = childNodes.length;
 

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js Mon Mar 22 21:58:18 2010
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,16 +19,29 @@
 
 /**
  * Iframe base Data Transfer Request Event class. This object is passed back to the listeners
- * of a Data Transfer Service Request. This object and TrXMLRequestEvent 
+ * of a Data Transfer Service Request. This object and TrXMLRequestEvent
  * support ITrXMLRequestEvent pseudo-interface
  * @ see TrXMLRequestEvent
  */
 function TrIFrameXMLRequestEvent(
-  iframeDoc)
+  iframeDoc,
+  source,
+  formId)
 {
   this._iframeDoc = iframeDoc;
+  this._source = source;
+  this._formId = formId;
 }
 
+TrIFrameXMLRequestEvent.prototype.getSource = function()
+{
+  return this._source;
+}
+
+TrIFrameXMLRequestEvent.prototype.getFormId = function()
+{
+  return this._formId;
+}
 
 TrIFrameXMLRequestEvent.prototype.getStatus = function()
 {
@@ -57,17 +70,30 @@ TrIFrameXMLRequestEvent.prototype.getRes
 * NOTE: this method is valid only for TrXMLRequestEvent.STATUS_COMPLETE
 **/
 TrIFrameXMLRequestEvent.prototype.getResponseText = function()
-{  
+{
   var agentIsIE = _agent.isIE;
   var iframeDoc = this._iframeDoc, xmlDocument = null;
 
   if(agentIsIE && iframeDoc.XMLDocument)
     xmlDocument = iframeDoc.XMLDocument;
-  else if(window.XMLDocument && (iframeDoc instanceof XMLDocument))
+  else if (window.XMLDocument && this._isResponseValidXML())
     xmlDocument = iframeDoc;
-    
+
   if(xmlDocument)
-    return AdfAgent.AGENT.getNodeXml(xmlDocument);
+  {
+    if (typeof XMLSerializer != "undefined")
+    {
+      return (new XMLSerializer()).serializeToString(xmlDocument);
+    }
+    else if (agentIsIE)
+    {
+      return xmlDocument.xml;
+    }
+  else
+    {
+      return null;
+    }
+  }
   else
     return iframeDoc.documentElement.innerHTML;
 }
@@ -81,6 +107,8 @@ TrIFrameXMLRequestEvent.prototype._isRes
     return true;
   else if(window.XMLDocument && (iframeDoc instanceof XMLDocument))
     return true;
+  else if (_agent.isSafari && iframeDoc.xmlVersion != null)
+    return true;
   else
     return false;
 }
@@ -96,30 +124,31 @@ TrIFrameXMLRequestEvent.prototype.getRes
 }
 
 /**
-* Returns if whether if is a rich response
+* Returns if whether if is a PPR response
 * NOTE: this method is valid only for TrXMLRequestEvent.STATUS_COMPLETE
 **/
 TrIFrameXMLRequestEvent.prototype.isPprResponse = function()
 {
   var agentIsIE = _agent.isIE;
   var iframeDoc = this._iframeDoc;
-  var isRichReponse = false;
-  
-  // Look for "Adf-Rich-Response-Type" PI
+  var pprResponse = false;
+
+  // Look for "Tr-XHR-Response-Type" PI
   if(agentIsIE && iframeDoc.XMLDocument)
   {
     var xmlDocument = iframeDoc.XMLDocument, childNodes = xmlDocument.childNodes;
+    console.log(xmlDocument);
     // In IE the xml PI is the first node
-    if(childNodes.length >= 2 && childNodes[1].nodeName ==  "Tr-XHR-Response-Type")
-      isRichReponse = true;
+    if(childNodes.length >= 2 && childNodes[1].nodeName ==  "partial-response")
+      pprResponse = true;
   }
   else
   {
-    if(iframeDoc.firstChild && iframeDoc.firstChild.nodeName ==  "Tr-XHR-Response-Type")
-      isRichReponse = true;
+    if(iframeDoc.firstChild && iframeDoc.firstChild.nodeName ==  "partial-response")
+      pprResponse = true;
   }
-  
-  return isRichReponse;
+
+  return pprResponse;
 }
 
 /**
@@ -130,6 +159,14 @@ TrIFrameXMLRequestEvent.prototype.getRes
 {
   if(this._isResponseValidXML())
     return "text/xml";
-    
+
   return "text/html";
-}
\ No newline at end of file
+}
+
+/**
+ * Returns if the request was made by the built in JSF AJAX APIs
+ */
+TrIFrameXMLRequestEvent.prototype.isJsfAjaxRequest = function()
+{
+  return false;
+};
\ No newline at end of file

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js Mon Mar 22 21:58:18 2010
@@ -61,7 +61,9 @@ TrRequestQueue._RequestItem = function(
   headerParams,
   content,
   method,
-  event
+  event,
+  source,
+  formId
   )
 {
   this._type = type;
@@ -71,6 +73,8 @@ TrRequestQueue._RequestItem = function(
   this._content = content;
   this._method = method;
   this._event = event;
+  this._source = source;
+  this._formId = formId;
 }
 
 TrRequestQueue.prototype._broadcastRequestStatusChanged = function(
@@ -98,11 +102,14 @@ TrRequestQueue.prototype._addRequestToQu
   actionURL,
   content,
   headerParams,
-  event
+  event,
+  source,
+  formId
   )
 {
   var newRequest = new TrRequestQueue._RequestItem(
-                          type, context, actionURL, headerParams, content, listener, event);
+                          type, context, actionURL, headerParams, content,
+                          listener, event, source, formId);
 
   if (this._useJsfBuiltInAjaxForXhr && type == TrRequestQueue._XMLHTTP_TYPE)
   {
@@ -120,7 +127,8 @@ TrRequestQueue.prototype._addRequestToQu
   {
     var dtsRequestEvent = new TrXMLRequestEvent(
                     TrXMLRequestEvent.STATUS_QUEUED,
-                    null); // no xmlhttp object at this time
+                    null, // no xmlhttp object at this time
+                    source);
 
     this._broadcastRequestStatusChanged(context, listener, dtsRequestEvent);
   }
@@ -163,10 +171,8 @@ TrRequestQueue.prototype.sendFormPost = 
   {
     pprURL = actionForm.getAttribute("_trinPPRAction");
   }
-  catch (e)
-  {
-  }
-  var action = pprURL?pprURL:actionForm.action;
+  catch (e) { ; }
+  var action = pprURL ? pprURL : actionForm.action;
 
   if (this._isMultipartForm(actionForm))
   {
@@ -187,12 +193,14 @@ TrRequestQueue.prototype.sendFormPost = 
       // gather the form values
       // TODO: log a warning if we're dropping any headers?  Or
       // come up with a hack to send "headers" via a multipart request?
-      this.sendRequest(context, method, action, params, headerParams, event);
+      this.sendRequest(context, method, action, params, headerParams, event,
+        params ? params.source : null, actionForm.id);
     }
     else
     {
       var content = this._getPostbackContent(actionForm, params);
-      this.sendRequest(context, method, action, content, headerParams, event);
+      this.sendRequest(context, method, action, content, headerParams, event,
+        params ? params.source : null, actionForm.id);
     }
   }
 }
@@ -385,6 +393,8 @@ TrRequestQueue._appendUrlFormEncoded = f
 * @param headerParams Option HTTP header parameters to attach to the request
 * @param content The content of the Asynchronous XML HTTP Post
 * @param event The browser event that triggered the request, if any
+* @param source The ID of the source element for the request
+* @param formId The ID of the form element
 */
 TrRequestQueue.prototype.sendRequest = function(
   context,
@@ -392,11 +402,13 @@ TrRequestQueue.prototype.sendRequest = f
   actionURL,
   content,
   headerParams,
-  event
+  event,
+  source,
+  formId
   )
 {
   this._addRequestToQueue(TrRequestQueue._XMLHTTP_TYPE, context, method, actionURL, content,
-    headerParams, event);
+    headerParams, event, source, formId);
 }
 
 /**
@@ -420,10 +432,10 @@ TrRequestQueue.prototype.sendMultipartRe
   var privateContext =
      {"htmlForm":htmlForm, "params": params, "context": context, "method": method};
 
-  this._addRequestToQueue(TrRequestQueue._MULTIPART_TYPE, privateContext, null, actionURL);
+  this._addRequestToQueue(TrRequestQueue._MULTIPART_TYPE, privateContext, null, actionURL,
+    params ? params.source : null, htmlForm.id);
 }
 
-
 TrRequestQueue.prototype._doRequest = function()
 {
   // currently we are posting only one request at a time. In future we may batch
@@ -455,6 +467,9 @@ TrRequestQueue.prototype._doXmlHttpReque
 
   xmlHttp.__dtsRequestContext = requestItem._context;
   xmlHttp.__dtsRequestMethod = requestItem._method;
+  xmlHttp.__dtsRequestSource = requestItem._source;
+  xmlHttp.__dtsRequestFormId = requestItem._formId;
+
   var callback = TrUIUtils.createCallback(this, this._handleRequestCallback);
   xmlHttp.setCallback(callback);
 
@@ -532,9 +547,12 @@ TrRequestQueue.prototype._doRequestThrou
     iframeDoc.removeChild(iframeDoc.firstChild);
 
   // store our context variables for later use
+  this._source = requestItem.params ?
+    requestItem.params["javax.faces.source"] : null;
   this._dtsContext = requestItem._context.context;
   this._dtsRequestMethod = requestItem._context.method;
   this._htmlForm = htmlForm;
+  this._dtsSource = requestItem._source;
   this._savedActionUrl = htmlForm.action;
   this._savedTarget = htmlForm.target;
 
@@ -547,14 +565,20 @@ TrRequestQueue.prototype._doRequestThrou
   htmlForm.target = frameName;
 
   this._appendParamNode(domDocument, htmlForm, "Tr-XHR-Message", "true");
-  // FIXME: the "partial" parameter is unnecessary
-  this._appendParamNode(domDocument, htmlForm, "partial", "true");
+  this._appendParamNode(domDocument, htmlForm, "javax.faces.partial.ajax", "true");
 
   if(params)
   {
+    if (params.source)
+    {
+      // Translate to JSF 2 payload
+      params["javax.faces.source"] = params.source;
+      delete params.source;
+    }
     for (var key in params)
     {
-      this._appendParamNode(domDocument, htmlForm, key, params[key]);
+      var paramValue = params[key];
+      this._appendParamNode(domDocument, htmlForm, key, paramValue);
     }
   }
 
@@ -631,6 +655,14 @@ TrRequestQueue.prototype._clearParamNode
   }
 }
 
+TrRequestQueue.prototype._isIFrameBlankHTML = function(iframeDoc)
+{
+  // In webkit browsers, the iframe load first with blank.html and will cause the
+  // code to incorrectly think the document is loaded when it is just the blank.html and
+  // the IFrame is still loading
+  return (_agent.isSafari && iframeDoc.documentURI == "about:blank");
+}
+
 TrRequestQueue.prototype._handleIFrameLoad = function()
 {
   var domDocument = this._getDomDocument();
@@ -651,7 +683,8 @@ TrRequestQueue.prototype._handleIFrameLo
   try
   {
     if(!iframeDoc.documentElement || !iframeDoc.documentElement.firstChild
-      || (agentIsIE && iframeDoc.readyState != "complete"))
+      || (agentIsIE && iframeDoc.readyState != "complete") ||
+      this._isIFrameBlankHTML(iframeDoc))
     {
       this._window.setTimeout(this._iframeLoadCallback, 50);
     }
@@ -679,7 +712,9 @@ TrRequestQueue.prototype._onIFrameLoadCo
   try
   {
     var dtsRequestEvent = new TrIFrameXMLRequestEvent(
-                              iframeDoc);
+                              iframeDoc,
+                              this._dtsSource,
+                              this._htmlForm.id);
 
     this._broadcastRequestStatusChanged(context, requestMethod,dtsRequestEvent);
   }
@@ -690,6 +725,7 @@ TrRequestQueue.prototype._onIFrameLoadCo
       iframeDoc.removeChild(iframeDoc.firstChild);
     this._htmlForm.action = this._savedActionUrl;
     this._htmlForm.target = this._savedTarget;
+    delete this._dtsSource;
     //clear the parameter nodes
     this._clearParamNodes();
     this._requestDone();
@@ -719,7 +755,7 @@ TrRequestQueue.prototype._handleRequestC
     // the Http connection  has been closed
   }
 
-  if ((status < 200 || status >= 300) && (statusCode != 0))
+  if ((statusCode < 200 || statusCode >= 300) && (statusCode != 0))
   {
     TrRequestQueue._alertError();
     TrRequestQueue._logError("Error StatusCode(",
@@ -734,7 +770,9 @@ TrRequestQueue.prototype._handleRequestC
     {
       var dtsRequestEvent = new TrXMLRequestEvent(
                   TrXMLRequestEvent.STATUS_COMPLETE,
-                  xmlHttp);
+                  xmlHttp,
+                  xmlHttp.__dtsRequestSource,
+                  xmlHttp.__dtsRequestFormId);
       this._broadcastRequestStatusChanged(
         xmlHttp.__dtsRequestContext,
         xmlHttp.__dtsRequestMethod,
@@ -840,6 +878,11 @@ TrRequestQueue.prototype.getDTSState = f
   return this._state;
 }
 
+TrRequestQueue.prototype.__useJsfBuiltInAjaxForXhr = function()
+{
+  return this._useJsfBuiltInAjaxForXhr;
+}
+
 /**
  * broadcast the state change of the request queue to its listeners
  */
@@ -905,6 +948,9 @@ TrRequestQueue._logWarning = function(va
 TrRequestQueue._logError = function(varArgs)
 {
   if (window.console && console.error)
+  {
     console.error(arguments);
+  }
+
   // else???
-}
+}
\ No newline at end of file

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js?rev=926369&r1=926368&r2=926369&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js Mon Mar 22 21:58:18 2010
@@ -25,11 +25,15 @@
  */
 function TrXMLRequestEvent(
   status,
-  request
+  request,
+  source,
+  formId
   )
 {
   this._status = status;
   this._request = request;
+  this._source = source;
+  this._formId = formId;
 }
 
 TrXMLRequestEvent.STATUS_QUEUED = 1;
@@ -37,11 +41,21 @@ TrXMLRequestEvent.STATUS_SEND_BEFORE = 2
 TrXMLRequestEvent.STATUS_SEND_AFTER = 3;
 TrXMLRequestEvent.STATUS_COMPLETE = 4;
 
+TrXMLRequestEvent.prototype.getFormId = function()
+{
+  return this._formId;
+}
+
 TrXMLRequestEvent.prototype.getStatus = function()
 {
   return this._status;
 }
 
+TrXMLRequestEvent.prototype.getSource = function()
+{
+  return this._source;
+}
+
 /**
 * Returns the response of the AJAX Request as an XML document
 * NOTE: this method is valid only for TrXMLRequestEvent.STATUS_COMPLETE