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/19 16:33:02 UTC

svn commit: r925280 - in /myfaces/trinidad/branches/jsf2_ajax.2: trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/ trinidad-examples/trinidad-demo/src/main/webapp/demos/ trinidad-impl/src/main/conf/META-INF/ trinidad-impl/src/main/java/org/apach...

Author: mstarets
Date: Fri Mar 19 15:33:01 2010
New Revision: 925280

URL: http://svn.apache.org/viewvc?rev=925280&view=rev
Log:
Merged in the old jsf2_ajax branch

Added:
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
      - copied unchanged from r924837, myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextFactoryImpl.java
      - copied unchanged from r924837, myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextFactoryImpl.java
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java
      - copied, changed from r924837, myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java
Modified:
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/web.xml
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/conf/META-INF/faces-config-base.xml
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandLinkRenderer.java
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HeadRenderer.java
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js
    myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/trinidad-config.xml Fri Mar 19 15:33:01 2010
@@ -19,7 +19,7 @@
 	   
 -->
 <trinidad-config xmlns="http://myfaces.apache.org/trinidad/config">
-  <debug-output>true</debug-output>
+  <!--debug-output>true</debug-output-->
   <!-- Uncomment to switch back to ALERT style client-side validation,
     or set to DISABLED to disable it altogether
   <client-validation>ALERT</client-validation>

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/web.xml?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/web.xml Fri Mar 19 15:33:01 2010
@@ -29,13 +29,6 @@
     <param-value>Development</param-value>
   </context-param>
 
-  <!-- *IF* we execute this demo in JSF2 / JavaEE 6 env, we want to use
-       the "OLD" Facelet version -->
-  <context-param>
-    <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
-    <param-value>true</param-value>
-  </context-param>
-
   <context-param>
     <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
     <param-value>.jspx</param-value>
@@ -74,10 +67,10 @@
 
   <!-- Trinidad by default uses an optimized client-side state saving
        mechanism. To disable that, uncomment the following -->
-  <!--context-param>
+  <context-param>
     <param-name>org.apache.myfaces.trinidad.CLIENT_STATE_METHOD</param-name>
-    <param-value>all</param-value>
-  </context-param-->
+    <param-value>token</param-value>
+  </context-param>
 <!-- When token client-side state saving is enabled, MyFaces Trinidad can apply an additional
      optimization by caching an entire UIViewRoot tree with each token. 
      (Note that this does not affect thread safety or session failover.) 
@@ -107,9 +100,8 @@
 
   <context-param>
     <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
-    <param-value>*.xhtml</param-value>
     <!-- to run facelets for jspx files comment the line above and uncomment line below-->
-    <!--param-value>*.xhtml;*.jspx</param-value-->
+    <param-value>*.xhtml;*.jspx</param-value>
   </context-param>
 
   <context-param>

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/conf/META-INF/faces-config-base.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/conf/META-INF/faces-config-base.xml?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/conf/META-INF/faces-config-base.xml (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/conf/META-INF/faces-config-base.xml Fri Mar 19 15:33:01 2010
@@ -42,6 +42,9 @@
     <view-declaration-language-factory>
       org.apache.myfaces.trinidadinternal.application.ViewDeclarationLanguageFactoryImpl
     </view-declaration-language-factory>
+    <partial-view-context-factory>
+      org.apache.myfaces.trinidadinternal.context.PartialViewContextFactoryImpl
+    </partial-view-context-factory>
   </factory>
 
   <lifecycle>

Copied: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java (from r924837, myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java)
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java?p2=myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java&p1=myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java&r1=924837&r2=925280&rev=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/PartialViewContextImpl.java Fri Mar 19 15:33:01 2010
@@ -41,10 +41,10 @@ import javax.faces.context.ResponseWrite
 import javax.faces.event.PhaseId;
 
 import org.apache.myfaces.trinidad.component.UIXComponent;
-import org.apache.myfaces.trinidad.component.visit.VisitCallback;
-import org.apache.myfaces.trinidad.component.visit.VisitContext;
-import org.apache.myfaces.trinidad.component.visit.VisitHint;
-import org.apache.myfaces.trinidad.component.visit.VisitResult;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitHint;
+import javax.faces.component.visit.VisitResult;
 import org.apache.myfaces.trinidad.context.PartialPageContext;
 import org.apache.myfaces.trinidad.context.RenderingContext;
 import org.apache.myfaces.trinidad.context.RequestContext;

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java Fri Mar 19 15:33:01 2010
@@ -143,11 +143,23 @@ public class CoreRenderKit extends Rende
     return "org.apache.myfaces.trinidad.core.desktop";
   }
 
+  /**
+   * Return <code>true</code> if the request header <code>Faces-Request</code> is present with the 
+   * value <code>partial/ajax</code>. Otherwise, return <code>false</code>.
+   * 
+   * @param ec the ExternalContext instance.
+   * @return
+   */
   static public boolean isAjaxRequest(ExternalContext ec)
   {
-    return "true".equals(ec.getRequestHeaderMap().get(_PPR_REQUEST_HEADER));
+    return _PARTIAL_AJAX.equals(ec.getRequestHeaderMap().get(_FACES_REQUEST_HEADER));
   }
 
+  /**
+   * TODO: Use JSF2.0 <code>Faces-Request</code> parameter.
+   * @param parameters
+   * @return
+   */
   static public boolean isPartialRequest(Map<String, String[]> parameters)
   {
     String[] array = parameters.get(_PPR_REQUEST_HEADER);
@@ -156,6 +168,11 @@ public class CoreRenderKit extends Rende
     return "true".equals(array[0]);
   }
 
+  /**
+   * TODO: Use JSF2.0 <code>Faces-Request</code> parameter.
+   * @param ec
+   * @return
+   */
   static public boolean isPartialRequest(ExternalContext ec)
   {
     // A partial request could be an AJAX request, or it could
@@ -803,6 +820,9 @@ public class CoreRenderKit extends Rende
   static private final String _SCRIPT_LIST_KEY =
     "org.apache.myfaces.trinidadinternal.renderkit.ScriptList";
   static private final String _PPR_REQUEST_HEADER = "Tr-XHR-Message";
+  private static final String _FACES_REQUEST_HEADER = "Faces-Request";
+  private static final String _PARTIAL_AJAX = "partial/ajax";
+
 
   static private final String _USE_DIALOG_POPUP_INIT_PARAM =
     "org.apache.myfaces.trinidad.ENABLE_LIGHTWEIGHT_DIALOGS";

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/ppr/PPRResponseWriter.java Fri Mar 19 15:33:01 2010
@@ -23,11 +23,13 @@ import java.io.IOException;
 import java.io.Writer;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
+import javax.faces.context.PartialResponseWriter;
 import javax.faces.context.ResponseWriter;
 
 import org.apache.myfaces.trinidad.context.PartialPageContext;
@@ -36,6 +38,7 @@ import org.apache.myfaces.trinidad.loggi
 import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
 import org.apache.myfaces.trinidad.util.Service;
 
+import org.apache.myfaces.trinidadinternal.io.ResponseWriterDecorator;
 import org.apache.myfaces.trinidadinternal.renderkit.core.pages.GenericEntry;
 
 /**
@@ -48,7 +51,7 @@ import org.apache.myfaces.trinidadintern
  * TODO: write out fragments only once we've detected the
  * ID, to avoid sending unnecessary fragments
  */
-public class PPRResponseWriter extends ScriptBufferingResponseWriter
+public class PPRResponseWriter extends ResponseWriterDecorator // ScriptBufferingResponseWriter
 {
   public PPRResponseWriter(ResponseWriter     out,
                            RenderingContext   rc)
@@ -68,7 +71,7 @@ public class PPRResponseWriter extends S
   PPRResponseWriter(ResponseWriter out,
                     PPRResponseWriter base)
   {
-    super(out, base);
+    super(out);
     // New XmlResponseWriter
     _xml        = new XmlResponseWriter(out, out.getCharacterEncoding());
     // But the rest of the state is shared
@@ -116,9 +119,10 @@ public class PPRResponseWriter extends S
     // Stick another PI indicating that this is a rich reponse
     // Used for an Iframe based communication channel, since it cannot 
     // read response headers
-    _xml.write("<?Tr-XHR-Response-Type ?>\n");
+    // TODO: Do we need this?
+    // _xml.write("<?Tr-XHR-Response-Type ?>\n");
 
-    _xml.startElement("content", null);
+    _xml.startElement(_ELEMENT_PARTIAL_RESPONSE, null);
     String viewId = _facesContext.getViewRoot().getViewId();
     // HACK: don't write out an "action" for PPR on a GenericEntry page
     // (basically entirely for the InlineDatePicker case)
@@ -132,8 +136,9 @@ public class PPRResponseWriter extends S
     }
 
     // TODO: Portlet support for PPR?
-
-    _xml.writeText(" ", null);
+    // TODO: PS - Not sure why this extra space is being written out, but this causes an 'malformed 
+    // XML error to be thrown by JSF 2 Ajax. Commented out the line.
+    // _xml.writeText(" ", null);
 
     _state.documentStarting = false;
   }
@@ -141,12 +146,13 @@ public class PPRResponseWriter extends S
   public void endDocument() throws IOException
   {
     // Write out any buffered <script src=""> or inline scripts
-    writeBufferedScripts();
+    // TODO: No need to write buffered scripts as we directly let script pass through
+    // writeBufferedScripts();
     
     // Write out all of the framework-level scripts
     writeFrameworkScripts();
-    
-    _xml.endElement("content");
+    _endChanges();
+    _xml.endElement(_ELEMENT_PARTIAL_RESPONSE);
     _xml.endDocument();
 
     // Force "inside target mode" - this is for Facelets,
@@ -311,9 +317,49 @@ public class PPRResponseWriter extends S
     return _xml;
   }
   
+  
+  public void endUpdate() throws IOException
+  {
+    super.flush();
+
+    if (_state._allowedUpdateStarted)
+    {
+      _xml.write("]]>");
+      _xml.endElement(_ELEMENT_CHANGES_UPDATE);
+      _xml.flush();
+      _state._allowedUpdateStarted = false;
+    }
+  }
+  
+ 
+  /**
+   * Starts an update element for non-PPR based content. For e.g., for rendering out the 
+   * "javax.faces.ViewState" id.
+   * @param id the id to use for the update element
+   */
+  public void startUpdate(String id) throws IOException 
+  {
+    if (id != null && _allowedIds.contains(id))
+    {
+      _startChanges();
+      
+      if (!_state._allowedUpdateStarted)
+      {
+        _state._allowedUpdateStarted = true;
+        _xml.startElement(_ELEMENT_CHANGES_UPDATE, null);
+        _xml.writeAttribute(_ATTRIBUTE_ID, id, null);
+        _xml.write("<![CDATA[");
+        _xml.flush();
+      }
+    }
+  }  
+
+  
   /*
    * Writes out buffered inline scripts and script libraries
    */
+  
+/*  
   protected void writeBufferedScripts() throws IOException
   {
     List<String> libraries = getBufferedLibraries();
@@ -332,17 +378,18 @@ public class PPRResponseWriter extends S
     {
       for (String script : scripts)
       {
-        _xml.startElement("script", null);
+        _xml.startElement(_ELEMENT_EVAL, null);
         _xml.write("<![CDATA[");
         _xml.write(script);
         _xml.write("]]>");
-        _xml.endElement("script");
+        _xml.endElement(_ELEMENT_EVAL);
       }
     }
 
     // Clear out any buffered scripts/libraries
     clearBufferedContents();
   }
+*/ 
   
   /*
    * Writes out framework-level scripts
@@ -391,7 +438,7 @@ public class PPRResponseWriter extends S
     if (tag != null)
     {
       super.flush();
-      tag.start(_state.pprContext, elementName);
+      tag.startUpdate(_state.pprContext, elementName);
     }
 
     _state.componentStack.add(tag);
@@ -405,7 +452,7 @@ public class PPRResponseWriter extends S
     componentStack.remove(pos);
 
     if (tag != null)
-      tag.finish(_state.pprContext, elementName);
+      tag.finishUpdate(_state.pprContext, elementName);
   }
 
   private boolean _isInsideTarget()
@@ -414,7 +461,8 @@ public class PPRResponseWriter extends S
     // a partial target subtree.  Otherwise, we discard all
     // output.
     return _state.forceInsideTarget ||
-           _state.pprContext.isInsidePartialTarget();
+           _state.pprContext.isInsidePartialTarget() ||
+           _state._allowedUpdateStarted;
            
   }
 
@@ -468,7 +516,24 @@ public class PPRResponseWriter extends S
     }
   }
 
+  private void _startChanges() throws IOException
+  {
+    if (!_state.changesStarted)
+    {
+      _xml.startElement(_ELEMENT_CHANGES, null);
+      _state.changesStarted = true;
+    }
+  }
 
+  private void _endChanges()
+    throws IOException
+  {
+    if (_state.changesStarted)
+    {
+      _xml.endElement("changes");
+      _state.changesStarted = false;
+    }
+  }
   //
   // Class representing PPR behavior associated with a tag.  The
   // base class simply tells PPR when it's working with a partial target
@@ -480,14 +545,16 @@ public class PPRResponseWriter extends S
       _id = id;
     }
 
-    public void start(
+    public void startUpdate(
       PartialPageContextImpl pprContext,
       String             elementName) throws IOException
     {
       if (_id != null)
       {
+        _startChanges();
         pprContext.pushRenderedPartialTarget(_id);
-        _xml.startElement("fragment",null);
+        _xml.startElement(_ELEMENT_CHANGES_UPDATE, null);
+        _xml.writeAttribute(_ATTRIBUTE_ID, _id, null);
         _xml.write("<![CDATA[");
         _xml.flush(); // NEW
 
@@ -501,7 +568,7 @@ public class PPRResponseWriter extends S
       }
     }
 
-    public void finish(
+    public void finishUpdate(
       PartialPageContextImpl pprContext,
       String             elementName) throws IOException
     {
@@ -520,7 +587,7 @@ public class PPRResponseWriter extends S
         PPRResponseWriter.super.flush();
       
         _xml.write("]]>");
-        _xml.endElement("fragment");
+        _xml.endElement(_ELEMENT_CHANGES_UPDATE);
         _xml.flush();
         
         pprContext.popRenderedPartialTarget();
@@ -567,11 +634,6 @@ public class PPRResponseWriter extends S
     private String _id;
   }
 
-  
-  private State _state;
-  private ResponseWriter _xml;
-  private final FacesContext _facesContext =
-   FacesContext.getCurrentInstance();
 
   static private class State
   {
@@ -585,9 +647,22 @@ public class PPRResponseWriter extends S
     public int           elementDepth;
     public boolean       documentStarted;
     public boolean       documentStarting;
+    public boolean       changesStarted;
+    private boolean      _allowedUpdateStarted;
     public final List<PPRTag> componentStack = new ArrayList<PPRTag>(50);
     public final PartialPageContextImpl pprContext;
   }
 
+  private State _state;
+  private ResponseWriter _xml;
+  private final FacesContext _facesContext = FacesContext.getCurrentInstance();
+  
   static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(PPRResponseWriter.class);
+  private static final String _ELEMENT_PARTIAL_RESPONSE = "partial-response";
+  private static final String _ELEMENT_CHANGES = "changes";
+  private static final String _ELEMENT_CHANGES_UPDATE = "update";
+  private static final String _ELEMENT_EVAL = "eval";
+  private static final String _ATTRIBUTE_ID = "id";
+  private static final List<String> _allowedIds = Arrays.asList(PartialResponseWriter.VIEW_STATE_MARKER);
+
 }

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandLinkRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandLinkRenderer.java?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandLinkRenderer.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CommandLinkRenderer.java Fri Mar 19 15:33:01 2010
@@ -77,7 +77,7 @@ public class CommandLinkRenderer extends
       Map<String, String> parameterMap =
         facesContext.getExternalContext().getRequestParameterMap();
 
-      Object source = parameterMap.get("source");
+      Object source = parameterMap.get("javax.faces.source");
       if (clientId == null)
       {
         clientId = component.getClientId(facesContext);

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java Fri Mar 19 15:33:01 2010
@@ -20,6 +20,7 @@ package org.apache.myfaces.trinidadinter
 
 import java.io.IOException;
 
+import javax.faces.application.ResourceDependency;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
@@ -34,6 +35,7 @@ import org.apache.myfaces.trinidad.rende
  * <p>
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/renderkit/core/xhtml/DocumentRenderer.java#0 $) $Date: 10-nov-2005.19:01:25 $
  */
+@ResourceDependency(target = "head", library = "javax.faces", name = "jsf.js")
 public class DocumentRenderer extends XhtmlRenderer
 {
   public DocumentRenderer()

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HeadRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HeadRenderer.java?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HeadRenderer.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/HeadRenderer.java Fri Mar 19 15:33:01 2010
@@ -20,6 +20,7 @@ package org.apache.myfaces.trinidadinter
 
 import java.io.IOException;
 
+import javax.faces.application.ResourceDependency;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -36,6 +37,7 @@ import org.apache.myfaces.trinidad.rende
  * <p>
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/renderkit/core/xhtml/HeadRenderer.java#0 $) $Date: 10-nov-2005.19:01:29 $
  */
+@ResourceDependency(target = "head", library = "javax.faces", name = "jsf.js")
 public class HeadRenderer extends XhtmlRenderer
 {
   public HeadRenderer()

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js Fri Mar 19 15:33:01 2010
@@ -1701,7 +1701,8 @@ function submitForm(
   form,
   doValidate,
   parameters,
-  isPartial
+  isPartial,
+  event
   )
 {
   // If we've delayed any sort of event submission, we won't want to do it at
@@ -1862,7 +1863,7 @@ function submitForm(
       }
       else
       {
-        TrPage.getInstance().sendPartialFormPost(form, parameters);
+        TrPage.getInstance().sendPartialFormPost(form, parameters, null, event);
       }
     }
     else
@@ -3636,7 +3637,6 @@ function _doPprStartBlocking (win)
 //
 function _pprStopBlocking(win)
 {
-
   // No blocking is performed on Nokia, PPC and BlackBerry devices
   if (_agent.isPIE || _agent.isNokiaPhone || _agent.isBlackBerry)
     return;
@@ -3868,7 +3868,8 @@ function _firePartialChange(url)
 function _submitPartialChange(
   form,
   doValidate,
-  parameters)
+  parameters,
+  event)
 {
   // If there's no PPR iframe, then just perform a normal,
   // full-page submission.
@@ -3886,10 +3887,10 @@ function _submitPartialChange(
   parameters = _addFormParameter(parameters, "partial", "true");
 
   // block all mouse clicks until the submit is done
-    _pprStartBlocking(window);
+  _pprStartBlocking(window);
 
   // Submit the form
-  var submitted = submitForm(form, doValidate, parameters, true);
+  var submitted = submitForm(form, doValidate, parameters, true, event);
 
   // If the form wasn't actually submitted, update the ref count
   if (!submitted)

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js Fri Mar 19 15:33:01 2010
@@ -18,11 +18,15 @@
  */
 function TrPage()
 {
+  if (typeof jsf != "undefined")
+  {
+    jsf.ajax.addOnEvent(TrUIUtils.createCallback(this, this._jsfAjaxCallback));
+  }
+
   this._loadedLibraries = TrPage._collectLoadedLibraries();
   this._requestQueue = new TrRequestQueue(window);
 }
 
-
 /**
  * Get the shared instance of the page object.
  */
@@ -53,11 +57,12 @@ TrPage.prototype.getRequestQueue = funct
 TrPage.prototype.sendPartialFormPost = function(
   actionForm,
   params,
-  headerParams)
+  headerParams,
+  event)
 {
   this.getRequestQueue().sendFormPost(
     this, this._requestStatusChanged,
-    actionForm, params, headerParams);
+    actionForm, params, headerParams, event);
 }
 
 TrPage.prototype._requestStatusChanged = function(requestEvent)
@@ -67,9 +72,9 @@ TrPage.prototype._requestStatusChanged =
     var statusCode = requestEvent.getResponseStatusCode();
 
     // The server might not return successfully, for example if an
-    // exception is thrown.  When that happens, a non-200 (OK) status
-    // code is returned as part of the HTTP prototcol.
-    if (statusCode == 200)
+    // exception is thrown. When that happens, a status that is below
+    // 200 or 300 or above is returned as part of the HTTP prototcol.
+    if (statusCode >= 200 && statusCode < 300)
     {
       _pprStopBlocking(window);
 
@@ -86,7 +91,14 @@ TrPage.prototype._requestStatusChanged =
         // Nokia browser is officially supported.
         if (responseDocument != null)
         {
-          this._handlePprResponse(responseDocument.documentElement);
+          if (requestEvent.isJsfAjaxRequest())
+          {
+            this._handleJsfAjaxResponse(requestEvent);
+          }
+          else
+          {
+            this._handlePprResponse(responseDocument.documentElement);
+          }
         }
       }
       else
@@ -101,8 +113,61 @@ TrPage.prototype._requestStatusChanged =
       // wrong - we should do the handling here
       _pprStopBlocking(window);
     }
+  }
+  if (requestEvent.isJsfAjaxRequest())
+  {
+    this._handleJsfAjaxResponse(requestEvent);
+  }
+}
 
+TrPage.prototype._handleJsfAjaxResponse = function(requestEvent)
+{
+  try
+  {
+    var statusCode = requestEvent.getResponseStatusCode();
+    if (statusCode >= 200 && statusCode < 300)
+    {
+      if (this._ajaxOldDomElements)
+      {
+        this._notifyDomReplacementListeners(this._ajaxOldDomElements);
+      }
+
+      if (this._activeNode)
+      {
+        var activeNode = this._activeNode;
+        delete this._activeNode;
+        var index = -1;
+        if (activeNode.id)
+        {
+          for (var i = 0, size = this._ajaxOldDomElements.length; i < size; ++i)
+          {
+            if (TrPage._isDomAncestorOf(activeNode, this._ajaxOldDomElements[i].element))
+            {
+              index = i;
+              break;
+            }
+          }
+          if (index >= 0)
+          {
+            activeNode = document.getElementById(activeNode.id);
+            window._trActiveElement = activeNode;
+            if (activeNode)
+            {
+              activeNode.focus();
+            }
+          }
+        }
+      }
+    }
+    // TODO: do we need to do any additional processing here, for instance,
+    // error processing?
+  }
+  finally
+  {
+    delete this._ajaxOldDomElements;
+    delete this._activeNode;
   }
+  
 }
 
 TrPage.prototype._handlePprResponse = function(documentElement)
@@ -749,6 +814,7 @@ TrPage._autoSubmit = function(formId, in
 
   // If onchange is used for validation, then first validate
   // just the current input
+
   var isValid = true;
   if (_TrEventBasedValidation)
     isValid = _validateInput(event, true);
@@ -761,6 +827,92 @@ TrPage._autoSubmit = function(formId, in
     params.event = "autosub";
     params.source = inputId;
 
-    _submitPartialChange(formId, validateForm, params);
+    _submitPartialChange(formId, validateForm, params, event);
   }
 }
+
+TrPage.prototype._jsfAjaxCallback = function(data)
+{
+  if (data.status == "complete")
+  {
+    // Collect the DOM elements that will be replaced to be able to fire the
+    // DOM replacement events.
+    // This information is used in the _handleJsfAjaxResponse function that is called
+    // as a result of the request queue firing the XMLRequestEvent.
+    this._ajaxOldDomElements = this._getDomToBeUpdated(data.responseCode, data.responseXML);
+    this._activeNode = _getActiveElement();
+  }
+}
+
+TrPage.prototype._notifyDomReplacementListeners = function(dataArray)
+{
+  var listeners = this._domReplaceListeners;
+  if (!listeners || listeners.length == 0)
+  {
+    return;
+  }
+  for (var i = 0, isize = dataArray.length; i < isize; ++i)
+  {
+    var oldElem = dataArray[i].element;
+    var id = dataArray[i].id;
+    var newElem = id == null ? document.body : document.getElementById(id);
+    for (var j = 0, jsize = listeners.length; j < jsize; ++j)
+    {
+      var currListener = listeners[j];
+      var currInstance = listeners[++j];
+      if (currInstance != null)
+      {
+        currListener.call(currInstance, oldElem, newElem);
+      }
+      else
+      {
+        currListener(oldElem, newElem);
+      }
+    }
+  }
+}
+
+TrPage.prototype._getDomToBeUpdated = function(status, responseXML)
+{
+  // check for a successful request
+  if (status < 200 || status >= 300)
+  {
+    return null;
+  }
+  // see if the response contains changes (not a redirect for example)
+  var nodes = responseXML.getElementsByTagName("partial-response");
+  var responseTypeNode = nodes.length ? nodes[0].firstChild : null;
+  if (!responseTypeNode || responseTypeNode.nodeName !== "changes")
+  {
+    return null;
+  }
+
+  var changeNodes = responseTypeNode.childNodes;
+  var oldElements = [];
+  for (var i = 0, size = changeNodes.length; i < size; ++i)
+  {
+    var node = changeNodes[i];
+    if (node.nodeName !== "update")
+    {
+      // We only care about updates as that is what Trinidad supported for the DOM
+      // replacement notification API
+      continue;
+    }
+
+    var id = node.getAttribute("id");
+    if (id == "javax.faces.ViewState")
+    {
+      continue;
+    }
+    if (id == "javax.faces.ViewRoot" || id == "javax.faces.ViewBody")
+    {
+      oldElements.push({ "id": null, "element": document.body });
+    }
+    else
+    {
+      oldElements.push({ "id": id, "element": document.getElementById(id) });
+    }
+  }
+
+  return oldElements;
+}

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js Fri Mar 19 15:33:01 2010
@@ -31,6 +31,9 @@ function TrRequestQueue(domWindow)
 
   // Stash away the DOM window for later reference.
   this._window = domWindow;
+  // TODO: set this via a web.xml configuration parameter as well as checking for presense of the
+  // JSF library
+  this._useJsfBuiltInAjaxForXhr = (typeof jsf != "undefined");
 }
 
 // Class constants
@@ -57,7 +60,8 @@ TrRequestQueue._RequestItem = function(
   actionURL,
   headerParams,
   content,
-  method
+  method,
+  event
   )
 {
   this._type = type;
@@ -66,6 +70,7 @@ TrRequestQueue._RequestItem = function(
   this._headerParams = headerParams;
   this._content = content;
   this._method = method;
+  this._event = event;
 }
 
 TrRequestQueue.prototype._broadcastRequestStatusChanged = function(
@@ -92,11 +97,23 @@ TrRequestQueue.prototype._addRequestToQu
   listener,
   actionURL,
   content,
-  headerParams
+  headerParams,
+  event
   )
 {
   var newRequest = new TrRequestQueue._RequestItem(
-                          type, context, actionURL, headerParams, content, listener);
+                          type, context, actionURL, headerParams, content, listener, event);
+
+  if (this._useJsfBuiltInAjaxForXhr && type == TrRequestQueue._XMLHTTP_TYPE)
+  {
+    // Since JSF 2 already has a queue, we need not queue the request here, instead we should
+    // immediately process the request
+    this._state = TrRequestQueue.STATE_BUSY;
+    this._broadcastStateChangeEvent(TrRequestQueue.STATE_BUSY);
+    this._doXmlHttpRequest(newRequest);
+    return;
+  }
+
   this._requestQueue.push(newRequest);
 
   try
@@ -131,7 +148,8 @@ TrRequestQueue.prototype.sendFormPost = 
   method,
   actionForm,
   params,
-  headerParams
+  headerParams,
+  event
   )
 {
   //this retrieves the action url for PPR.  Generally this will be the action property on
@@ -158,13 +176,24 @@ TrRequestQueue.prototype.sendFormPost = 
   }
   else
   {
-    var content = this._getPostbackContent(actionForm, params);
-
     // IE BUG, see TRINIDAD-704
     if(_agent.isIE)
       this._autoCompleteForm(actionForm);
 
-    this.sendRequest(context, method, action, content, headerParams);
+    if (this._useJsfBuiltInAjaxForXhr)
+    {
+      // JSF 2 AJAX will take the parameters and it will determine the form
+      // content itself, so we should not convert the data to a string or
+      // 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);
+    }
+    else
+    {
+      var content = this._getPostbackContent(actionForm, params);
+      this.sendRequest(context, method, action, content, headerParams, event);
+    }
   }
 }
 
@@ -349,22 +378,25 @@ TrRequestQueue._appendUrlFormEncoded = f
 
 /**
 * Performs Asynchronous XML HTTP Request with the Server
-* @param context    any object that is sent back to the callback when the request
+* @param context Any object that is sent back to the callback when the request
 *  is complete. This object can be null.
-* @param method   Javascript method
-* @param actionURL   the url to send the request to
-* @param headerParams  Option HTTP header parameters to attach to the request
-* @param content     the content of the Asynchronous XML HTTP Post
+* @param method Javascript method
+* @param actionURL The url to send the request to
+* @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
 */
 TrRequestQueue.prototype.sendRequest = function(
   context,
   method,
   actionURL,
   content,
-  headerParams
+  headerParams,
+  event
   )
 {
-  this._addRequestToQueue(TrRequestQueue._XMLHTTP_TYPE, context, method, actionURL, content, headerParams);
+  this._addRequestToQueue(TrRequestQueue._XMLHTTP_TYPE, context, method, actionURL, content,
+    headerParams, event);
 }
 
 /**
@@ -411,30 +443,42 @@ TrRequestQueue.prototype._doRequest = fu
 
 TrRequestQueue.prototype._doXmlHttpRequest = function(requestItem)
 {
-  var xmlHttp = new TrXMLRequest();
+  var xmlHttp;
+  if (this._useJsfBuiltInAjaxForXhr)
+  {
+    xmlHttp = new TrXMLJsfAjaxRequest(requestItem._event, requestItem._content);
+  }
+  else
+  {
+    xmlHttp = new TrXMLRequest();
+  }
+
   xmlHttp.__dtsRequestContext = requestItem._context;
   xmlHttp.__dtsRequestMethod = requestItem._method;
   var callback = TrUIUtils.createCallback(this, this._handleRequestCallback);
   xmlHttp.setCallback(callback);
 
-  // xmlhttp request uses the same charset as its parent document's charset.
-  // There is no need to set the charset.
-  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+  if (!this._useJsfBuiltInAjaxForXhr)
+  {
+    // xmlhttp request uses the same charset as its parent document's charset.
+    // There is no need to set the charset.
+    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 
-  var headerParams = requestItem._headerParams;
+    var headerParams = requestItem._headerParams;
 
-  if (headerParams != null)
-  {
-    for (var headerName in headerParams)
+    if (headerParams != null)
     {
-      var currHeader =  headerParams[headerName];
+      for (var headerName in headerParams)
+      {
+        var currHeader =  headerParams[headerName];
 
-      // handle array parameters by joining them together with comma separators
-      // Test if it's an array via the "join" method
-      if (currHeader["join"])
-        currHeader = currHeader.join(',')
+        // handle array parameters by joining them together with comma separators
+        // Test if it's an array via the "join" method
+        if (currHeader["join"])
+          currHeader = currHeader.join(',')
 
-      xmlHttp.setRequestHeader(headerName, currHeader);
+        xmlHttp.setRequestHeader(headerName, currHeader);
+      }
     }
   }
 
@@ -684,7 +728,7 @@ TrRequestQueue.prototype._handleRequestC
     // the Http connection  has been closed
   }
 
-  if ((statusCode != 200) && (statusCode != 0))
+  if ((statusCode < 200 || statusCode >= 300) && (statusCode != 0))
   {
     TrRequestQueue._alertError();
     TrRequestQueue._logError("Error StatusCode(",

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js Fri Mar 19 15:33:01 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
@@ -34,7 +34,6 @@ function TrXMLRequest()
   this.xmlhttp = TrXMLRequest._createXmlHttpRequest();
 }
 
-
 /**
 * Request state constants. See getCompletionState()
 **/
@@ -49,7 +48,7 @@ TrXMLRequest.COMPLETED = 4;
 * Parameters: isSynch - true if request should be synchronous,
 * false otherwise
 **/
-TrXMLRequest.prototype.setSynchronous = 
+TrXMLRequest.prototype.setSynchronous =
 function (isSynch)
 {
   this.isSynchronous = isSynch;
@@ -62,7 +61,7 @@ function (isSynch)
 * The callback should have the following siganture:
 * <void> function (<TrXMLRequest>request)
 **/
-TrXMLRequest.prototype.setCallback = 
+TrXMLRequest.prototype.setCallback =
 function (_callback)
 {
   this.callback = _callback;
@@ -92,7 +91,7 @@ function()
 * Note: this method will block if the the request is asynchronous and
 * has not yet been completed
 **/
-TrXMLRequest.prototype.getResponseXML = 
+TrXMLRequest.prototype.getResponseXML =
 function()
 {
   return this.xmlhttp.responseXML;
@@ -103,7 +102,7 @@ function()
 * Note: this method will block if the the request is asynchronous and
 * has not yet been completed
 **/
-TrXMLRequest.prototype.getResponseText = 
+TrXMLRequest.prototype.getResponseText =
 function()
 {
   return this.xmlhttp.responseText;
@@ -111,7 +110,7 @@ function()
 
 /**
 * Sends an XML HTTP request
-* Parameters: 
+* Parameters:
 * url - destination URL
 * content - XML document or string that should be included in the request's body
 **/
@@ -125,7 +124,7 @@ function(url, content)
     cb.obj = this;
     xmlhttp.onreadystatechange  = cb;
   }
-  
+
   var method = content ? "POST" : "GET";
   xmlhttp.open(method, url, !this.isSynchronous);
   for (var name in this.headers)
@@ -144,20 +143,20 @@ function(url, content)
 }
 
 
-TrXMLRequest.prototype.getResponseHeader = 
+TrXMLRequest.prototype.getResponseHeader =
 function(name)
 {
 
   return this.xmlhttp.getResponseHeader(name);
 }
 
-TrXMLRequest.prototype.getAllResponseHeaders = 
+TrXMLRequest.prototype.getAllResponseHeaders =
 function()
 {
   return this.xmlhttp.getAllResponseHeaders();
 }
 
-TrXMLRequest.prototype.setRequestHeader = 
+TrXMLRequest.prototype.setRequestHeader =
 function(name, value)
 {
   this.headers[name] = value;
@@ -206,4 +205,117 @@ TrXMLRequest.prototype.cleanup =function
   delete this.xmlhttp;
 }
 
+/**
+ * Wrapper for the JSF AJAX callback data that provides the same
+ * interface as TrXMLRequest to maintain a compatible API to ease
+ * the support of both the legacy code as well as code to integrate
+ * with JSF 2 AJAX
+ */
+function TrXMLJsfAjaxRequest(
+  event,
+  params)
+{
+  this.isSynchronous = false;
+  this.callback = null;
+  this._event = event;
+  this._params = params || new Object();
+  this._status = 0;
+  this._state = TrXMLRequest.UNINITIALIZED;
+}
+TrXMLJsfAjaxRequest.prototype.setCallback = function(value)
+{
+  this.callback = value;
+}
+TrXMLJsfAjaxRequest.prototype.getCompletionState = function()
+{
+  return this._state;
+}
+TrXMLJsfAjaxRequest.prototype.getStatus = function()
+{
+  return this._status;
+}
+TrXMLJsfAjaxRequest.prototype.getResponseXML = function()
+{
+  return this._responseXML;
+}
+TrXMLJsfAjaxRequest.prototype.getResponseText = function()
+{
+  return this._responseText;
+}
+TrXMLJsfAjaxRequest.prototype.cleanup = function()
+{
+  this.callback = null;
+}
+TrXMLJsfAjaxRequest.prototype._ajaxCallback = function(
+  data
+  )
+{
+  switch (data.status)
+  {
+    case "begin":
+      this._state = TrXMLRequest.LOADING;
+      break;
+    case "complete":
+      this._state = TrXMLRequest.LOADED;
+      break;
+    case "success":
+    default:
+      this._state = TrXMLRequest.COMPLETED;
+      break;
+  }
+
+  if (data.status != "begin")
+  {
+    this._status = data.responseCode;
+    this._responseXML = data.responseXML;
+    this._responseText = data.responseText;
+  }
 
+  if (this.callback)
+  {
+    this.callback(this);
+  }
+}
+TrXMLJsfAjaxRequest.prototype.__onerror = function(
+  data
+  )
+{
+  this._state = TrXMLRequest.COMPLETED;
+  this._status = data.responseCode;
+  this._responseXML = data.responseXML;
+  this._responseText = data.responseText;
+  if (this.callback)
+  {
+    this.callback(this);
+  }
+}
+TrXMLJsfAjaxRequest.prototype.send = function()
+{
+  var source = this._params.source ?
+    _getElementById(window.document, this._params.source) : null;
+
+  var ajaxCallback = TrUIUtils.createCallback(this, this._ajaxCallback);
+
+  jsf.ajax.request(
+    source,
+    this._event,
+    {
+      "onevent": ajaxCallback,
+      "onerror": ajaxCallback,
+      "params": this._params
+    });
+
+  // No need for the event anymore, release the resource
+  delete this._event;
+}
+// No-op functions:
+TrXMLJsfAjaxRequest.prototype.setSynchronous =
+TrXMLJsfAjaxRequest.prototype.setRequestHeader = function() {}
+TrXMLJsfAjaxRequest.prototype.getAllResponseHeaders = function()
+{
+  return new Object();
+};
+TrXMLJsfAjaxRequest.prototype.getResponseHeader = function()
+{
+  return null;
+};
\ No newline at end of file

Modified: myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js?rev=925280&r1=925279&r2=925280&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.2/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js Fri Mar 19 15:33:01 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
@@ -20,7 +20,7 @@
 /**
  * AJAX Request Event class. This object is passed back to the listeners
  * of a AJAX Service Request. It support ITrXMLRequestEvent pseudo-interface
- * with the following methods: getStatus, getResponseXML, getResponseText, 
+ * with the following methods: getStatus, getResponseXML, getResponseText,
  * isPprResponse, getResponseContentType
  */
 function TrXMLRequestEvent(
@@ -56,7 +56,7 @@ TrXMLRequestEvent.prototype.getResponseX
 * NOTE: this method is valid only for TrXMLRequestEvent.STATUS_COMPLETE
 **/
 TrXMLRequestEvent.prototype._isResponseValidXML = function()
-{         
+{
   // Note: Mozilla applies default XSLT to XML parse error
   var responseDocument = this._request.getResponseXML();
   if (!responseDocument)
@@ -81,7 +81,7 @@ TrXMLRequestEvent.prototype._isResponseV
 * NOTE: this method is valid only for TrXMLRequestEvent.STATUS_COMPLETE
 **/
 TrXMLRequestEvent.prototype.getResponseText = function()
-{  
+{
   return this._request.getResponseText();
 }
 
@@ -147,4 +147,12 @@ TrXMLRequestEvent.prototype.isPprRespons
 TrXMLRequestEvent.prototype.getResponseContentType = function()
 {
   this.getResponseHeader("Content-Type");
-}
\ No newline at end of file
+}
+
+/**
+ * Returns if the request was made by the built in JSF AJAX APIs
+ */
+TrXMLRequestEvent.prototype.isJsfAjaxRequest = function()
+{
+  return (this._request instanceof TrXMLJsfAjaxRequest);
+};
\ No newline at end of file