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/04/19 21:49:34 UTC

svn commit: r935715 - in /myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/ javascript/META-INF/adf/jsLibs/ javascript/META-INF/adf/jsLibs/xhr/

Author: mstarets
Date: Mon Apr 19 19:49:33 2010
New Revision: 935715

URL: http://svn.apache.org/viewvc?rev=935715&view=rev
Log:
Added an agent hook and a private context parameter for disabling PPR over JSF Ajax

Modified:
    myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/BodyRenderer.java
    myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
    myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
    myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js

Modified: myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/BodyRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/BodyRenderer.java?rev=935715&r1=935714&r2=935715&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/BodyRenderer.java (original)
+++ myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/BodyRenderer.java Mon Apr 19 19:49:33 2010
@@ -23,6 +23,7 @@ import java.beans.Beans;
 import java.io.IOException;
 
 import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
@@ -98,6 +99,8 @@ public class BodyRenderer extends PanelP
     context.getResponseWriter().endElement("body");
 
     _renderInitialFocusScript(context, rc);
+    
+    _renderDisableJsfAjaxScript(context, rc);
   }
 
   @Override
@@ -379,6 +382,27 @@ public class BodyRenderer extends PanelP
       writer.endElement("script");
     }
   }
+  
+  // Reverts to the legacy PPR channel (disables PPR over JSF Ajax)
+  // if teh conetxt parameter is set
+  private void _renderDisableJsfAjaxScript(
+    FacesContext     context,
+    RenderingContext rc
+    ) throws IOException 
+  {
+    if (!supportsScripting(rc))
+    {
+      return;
+    }
+    ExternalContext extContext = context.getExternalContext();
+    if ("off".equalsIgnoreCase(extContext.getInitParameter(_PPR_OVER_JSF_AJAX)))
+    {
+      ResponseWriter writer = context.getResponseWriter();
+      writer.startElement("script", null);
+      writer.write("TrPage.getInstance().__disablePprOverJsfAjax()");
+      writer.endElement("script");
+    }
+  }
 
   // If partial back is supported,
   // render a span with the _PPR_BACK_CONTENT_ID id.
@@ -577,4 +601,6 @@ public class BodyRenderer extends PanelP
   static private final String _PPR_BACK_SAVE_CONTENT_ID = "_pprSavePage";
   static private final String _PPR_BACK_SAVE_SCRIPT_ID = "_pprSaveScript";
   static private final String _PPR_BACK_SAVE_LIBRARY_ID = "_pprSaveLib";
+  
+  static private final String _PPR_OVER_JSF_AJAX = "org.apache.myfaces.trinidadinternal.PPR_OVER_JSF_AJAX";
 }

Modified: myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js?rev=935715&r1=935714&r2=935715&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js Mon Apr 19 19:49:33 2010
@@ -228,6 +228,10 @@ function _agentInit()
 
   // Indicate browser's PPR capability support
   var pprUnsupported    = false;
+  
+  // Indicate whether the browser and platform are capable of
+  // sending PPR requests via JSF Ajax
+  var useJsfAjax = true;
 
   // Flag to indicate that document object is sufficiently implemented to
   // provide good level of access to HTML, XHTML and XML document.
@@ -390,6 +394,7 @@ function _agentInit()
   _agent.isWindowsMobile6       = isWindowsMobile6;
   _agent.kind                   = kind;
   _agent.pprUnsupported         = pprUnsupported;
+  _agent.useJsfAjax             = useJsfAjax;
   _agent.supportsDomDocument    = supportsDomDocument;
   _agent.supportsNodeType       = supportsNodeType;
   _agent.supportsValidation     = supportsValidation;

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=935715&r1=935714&r2=935715&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 Mon Apr 19 19:49:33 2010
@@ -18,13 +18,8 @@
  */
 function TrPage()
 {
-  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();
 }
 
 TrPage._VIEW_STATE_ID = "javax.faces.ViewState";
@@ -58,7 +53,20 @@ TrPage.prototype.getRequestQueue = funct
  */
 TrPage.prototype.sendPartialFormPost = function (actionForm, params, headerParams, event)
 {
-  this.getRequestQueue().sendFormPost(this, this._requestStatusChanged, actionForm, params, headerParams, event);
+  var queue =this.getRequestQueue();
+  if (!this._xhrInited)
+  {
+    this._xhrInited = true;
+    if (this._noPprOverJsfAjax)
+    {
+      queue.__disableJsfBuiltInAjaxForXhr();
+    }
+    else if (queue.__useJsfBuiltInAjaxForXhr())
+    {
+      jsf.ajax.addOnEvent(TrUIUtils.createCallback(this, this._jsfAjaxCallback));
+    }
+  }
+  queue.sendFormPost(this, this._requestStatusChanged, actionForm, params, headerParams, event);
 }
 
 TrPage.prototype._requestStatusChanged = function (requestEvent)
@@ -238,6 +246,11 @@ TrPage.prototype._handlePprResponse = fu
   }
 }
 
+TrPage.prototype.__disablePprOverJsfAjax = function()
+{
+  this._noPprOverJsfAjax = true;
+}
+
 TrPage.prototype._addResetFields = function (formName, resetNames)
 {
   // Create the necessary objects

Modified: myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js?rev=935715&r1=935714&r2=935715&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js (original)
+++ myfaces/trinidad/branches/jsf2_ajax.3/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js Mon Apr 19 19:49:33 2010
@@ -33,7 +33,7 @@ function TrRequestQueue(domWindow)
   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");
+  this._useJsfBuiltInAjaxForXhr = (_agent.useJsfAjax && typeof jsf != "undefined");
 }
 
 // Class constants
@@ -906,6 +906,11 @@ TrRequestQueue.prototype.__useJsfBuiltIn
   return this._useJsfBuiltInAjaxForXhr;
 }
 
+TrRequestQueue.prototype.__disableJsfBuiltInAjaxForXhr = function()
+{
+  this._useJsfBuiltInAjaxForXhr = false;
+}
+
 /**
  * broadcast the state change of the request queue to its listeners
  */