You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by aw...@apache.org on 2007/06/08 01:31:57 UTC
svn commit: r545348 - in
/myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs:
Core.js Page.js xhr/IFrameXMLRequestEvent.js xhr/RequestQueue.js
xhr/XMLRequest.js xhr/XMLRequestEvent.js
Author: awiner
Date: Thu Jun 7 16:31:56 2007
New Revision: 545348
URL: http://svn.apache.org/viewvc?view=rev&rev=545348
Log:
TRINIDAD-46: Checkpoint for PPR via XMLHttp
- Refactor the RequestQueue listener code so that it takes a context and function object instead of expecting an explicit JS function name
- Reorder function parameters in general to make more sense
- Add a TrPage.sendFormPost(formObj, formParams, headerParams) method to make sending an XHR request easy
- Fix Internet Explorer support
Modified:
myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js
myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js
myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js
Modified: myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js?view=diff&rev=545348&r1=545347&r2=545348
==============================================================================
--- myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js (original)
+++ myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js Thu Jun 7 16:31:56 2007
@@ -1746,8 +1746,7 @@
if (isPartial)
{
- TrRequestQueue.getInstance().sendFormPost(window, form, null,
- parameters, TrPage.getInstance());
+ TrPage.getInstance().sendFormPost(form, parameters);
}
else
{
@@ -3374,6 +3373,29 @@
}
}
+//
+// _pprConsumeClick: Helps implement blocking. This function just consumes
+// every click that falls within the body.
+//
+function _pprConsumeClick(event)
+{
+ if (_agent.isIE)
+ {
+ var body = document.body;
+ if ((event.x < body.offsetLeft) || (event.y < body.offsetTop)
+ || (event.x > body.offsetWidth) || (event.y > body.offsetHeight))
+ {
+ // OK, we've caught an event outside the body of the document. Assume
+ // that the user is clicking somewhere on the menu bar, or another
+ // window. At this point, we release the mouse and continue (that's
+ // better than keeping the user in limbo).
+
+ _pprStopBlocking(window);
+ }
+ }
+ return false;
+}
+
//
// _pprStartBlocking: Starts consuming every click (to implement blocking)
@@ -3519,6 +3541,31 @@
}
}
return rv;
+}
+
+
+//
+// _pprConsumeFirstClick: Helps implement blocking.
+//
+// On IE, the capture doesn't allow us to hand off the first click - we can
+// only eat it, but attachEvent only allows us to do something with the event
+// AFTER it's been delivered to the element. There's no way to make a decision
+// whether or not to deliver a particular event. Therefore, since we want to
+// deliver the first click, and block everything else, we attachEvent using
+// this handler. This handler then just immediately switches over the the
+// capture. This function is only used on IE.
+//
+function _pprConsumeFirstClick(event)
+{
+ // This is an IE only function
+ if (_agent.isIE)
+ {
+ // switch over to capture
+ _pprControlCapture(window, true);
+ // and remove this one-time function
+ window.document.detachEvent('onclick', _pprConsumeFirstClick);
+ }
+ return false;
}
Modified: myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js?view=diff&rev=545348&r1=545347&r2=545348
==============================================================================
--- myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js (original)
+++ myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js Thu Jun 7 16:31:56 2007
@@ -33,7 +33,26 @@
return TrPage._INSTANCE;
}
-TrPage.prototype.requestStatusChanged = function(requestEvent)
+/**
+ * Post the form for partial postback. Supports both standard AJAX
+ * posts and, for multipart/form posts, IFRAME-based transmission.
+ * @param actionForm{FormElement} the HTML form to post
+ * @param params{Object} additional parameters to send
+ * @param headerParams{Object} HTTP headers to include (ignored if
+ * the request must be a multipart/form post)
+ */
+// TODO rename?
+TrPage.prototype.sendFormPost = function(
+ actionForm,
+ params,
+ headerParams)
+{
+ TrRequestQueue.getInstance().sendFormPost(
+ this, this._requestStatusChanged,
+ actionForm, params, headerParams);
+}
+
+TrPage.prototype._requestStatusChanged = function(requestEvent)
{
if (requestEvent.getStatus() == TrXMLRequestEvent.STATUS_COMPLETE)
{
Modified: myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js?view=diff&rev=545348&r1=545347&r2=545348
==============================================================================
--- myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js (original)
+++ myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/IFrameXMLRequestEvent.js Thu Jun 7 16:31:56 2007
@@ -24,12 +24,9 @@
* @ see TrXMLRequestEvent
*/
function TrIFrameXMLRequestEvent(
- iframeDoc,
- context
- )
+ iframeDoc)
{
this._iframeDoc = iframeDoc;
- this._context = context;
}
@@ -39,10 +36,6 @@
return TrXMLRequestEvent.STATUS_COMPLETE;
}
-TrIFrameXMLRequestEvent.prototype.getContext = function()
-{
- return this._context;
-}
/**
* Returns the response of the Data Transfer Request as an XML document
Modified: myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js?view=diff&rev=545348&r1=545347&r2=545348
==============================================================================
--- myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js (original)
+++ myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/RequestQueue.js Thu Jun 7 16:31:56 2007
@@ -65,7 +65,7 @@
actionURL,
headerParams,
content,
- listener
+ method
)
{
this._type = type;
@@ -73,22 +73,23 @@
this._actionURL = actionURL;
this._headerParams = headerParams;
this._content = content;
- this._listener = listener;
+ this._method = method;
}
-TrRequestQueue.prototype._broadcastRequestStatusChanged = function(currListener, event)
+TrRequestQueue.prototype._broadcastRequestStatusChanged = function(
+ context, currMethod, event)
{
- if (currListener.requestStatusChanged)
+ if (currMethod)
{
try
{
- currListener.requestStatusChanged(event);
+ currMethod.call(context, event);
}
catch (e)
{
TrRequestQueue._logError(
"Error ", e, " delivering XML request status changed to ",
- currListener);
+ currMethod);
}
}
}
@@ -96,10 +97,10 @@
TrRequestQueue.prototype._addRequestToQueue = function(
type,
context,
+ listener,
actionURL,
- headerParams,
content,
- listener
+ headerParams
)
{
var newRequest = new TrRequestQueue._RequestItem(
@@ -110,10 +111,9 @@
{
var dtsRequestEvent = new TrXMLRequestEvent(
TrXMLRequestEvent.STATUS_QUEUED,
- context,
null); // no xmlhttp object at this time
- this._broadcastRequestStatusChanged(listener,dtsRequestEvent);
+ this._broadcastRequestStatusChanged(context, listener, dtsRequestEvent);
}
catch(e)
{
@@ -135,21 +135,23 @@
* Send a form post
*/
TrRequestQueue.prototype.sendFormPost = function(
- context,
+ context,
+ method,
actionForm,
- headerParams,
params,
- listener
+ headerParams
)
{
if (this._isMultipartForm(actionForm))
{
- this.sendMultipartRequest(context, actionForm.action, actionForm, params, listener);
+ // TODO: log a warning if we're dropping any headers? Or
+ // come up with a hack to send "headers" via a multipart request?
+ this.sendMultipartRequest(context, method, actionForm.action, actionForm, params);
}
else
{
var content = this._getPostbackContent(actionForm, params);
- this.sendRequest(context, actionForm.action, headerParams, content, listener);
+ this.sendRequest(context, method, actionForm.action, content, headerParams);
}
}
@@ -308,18 +310,17 @@
* @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 listener Object that implements XMLRequestListener interface
+* @param method Javascript method
*/
TrRequestQueue.prototype.sendRequest = function(
- context,
+ context,
+ method,
actionURL,
- headerParams,
content,
- listener
+ headerParams
)
{
- this._addRequestToQueue(TrRequestQueue._XMLHTTP_TYPE, context, actionURL, headerParams,
- content, listener);
+ this._addRequestToQueue(TrRequestQueue._XMLHTTP_TYPE, context, method, actionURL, content, headerParams);
}
/**
@@ -330,27 +331,20 @@
* @param htmlForm the form containing multi-part data. The action attribute
* of the form is used for send the request to the server
* @param params additional parameters that need to be sent to the server
-* @param listener Object that implements XMLRequestListener interface
+* @param method Javascript method
*/
TrRequestQueue.prototype.sendMultipartRequest = function(
context,
+ method,
actionURL,
- htmlForm,
- params,
- listener
+ htmlForm,
+ params
)
{
- if(context == null)
- {
- context = {"_htmlForm":htmlForm, "_params": params};
- }
- else
- {
- context._htmlForm = htmlForm;
- context._params = params;
- }
- this._addRequestToQueue(TrRequestQueue._MULTIPART_TYPE, context, actionURL, null,
- null, listener);
+ var privateContext =
+ {"htmlForm":htmlForm, "params": params, "context": context, "method": method};
+
+ this._addRequestToQueue(TrRequestQueue._MULTIPART_TYPE, privateContext, null, actionURL);
}
@@ -375,7 +369,7 @@
{
var xmlHttp = new TrXMLRequest();
xmlHttp.__dtsRequestContext = requestItem._context;
- xmlHttp.__dtsRequestListener = requestItem._listener;
+ xmlHttp.__dtsRequestMethod = requestItem._method;
xmlHttp.setCallback(TrRequestQueue._requestCallback);
// xmlhttp request uses the same charset as its parent document's charset.
@@ -404,9 +398,9 @@
TrRequestQueue.prototype._doRequestThroughIframe = function(requestItem)
{
- var htmlForm = requestItem._context._htmlForm;
+ var htmlForm = requestItem._context.htmlForm;
var actionURL = requestItem._actionURL;
- var params = requestItem._context._params;
+ var params = requestItem._context.params;
// assert(htmlForm.action, "form action cannot be null for multiform post");
var frameName = TrRequestQueue._MULTIPART_FRAME;
var domDocument = this._getDomDocument();
@@ -428,8 +422,9 @@
if (agentIsIE)
{
+ // Why these lines happen to work, I can't say - but remove them,
+ // and the postback actually goes to a new window
hiddenFrame = domDocument.frames[frameName];
- // Since we are using the same name as id
hiddenFrame.name = frameName;
iframeDoc = hiddenFrame.document;
}
@@ -448,8 +443,8 @@
iframeDoc.removeChild(iframeDoc.firstChild);
// store our context variables for later use
- this._dtsContext = requestItem._context;
- this._dtsRequestlistener = requestItem._listener;
+ this._dtsContext = requestItem._context.context;
+ this._dtsRequestMethod = requestItem._context.method;
this._htmlForm = htmlForm;
this._savedActionUrl = htmlForm.action;
this._savedTarget = htmlForm.target;
@@ -546,7 +541,7 @@
else
{
this._onIFrameLoadComplete(iframeDoc, this._dtsContext,
- this._dtsRequestlistener);
+ this._dtsRequestMethod);
}
}
catch(e)
@@ -563,15 +558,14 @@
TrRequestQueue.prototype._onIFrameLoadComplete = function(
iframeDoc,
context,
- requestListener)
+ requestMethod)
{
try
{
var dtsRequestEvent = new TrIFrameXMLRequestEvent(
- iframeDoc,
- context);
+ iframeDoc);
- this._broadcastRequestStatusChanged(requestListener,dtsRequestEvent);
+ this._broadcastRequestStatusChanged(context, requestMethod,dtsRequestEvent);
}
finally
{
@@ -624,10 +618,11 @@
{
var dtsRequestEvent = new TrXMLRequestEvent(
TrXMLRequestEvent.STATUS_COMPLETE,
- xmlHttp.__dtsRequestContext,
xmlHttp);
-
- this._broadcastRequestStatusChanged(xmlHttp.__dtsRequestListener,dtsRequestEvent);
+ this._broadcastRequestStatusChanged(
+ xmlHttp.__dtsRequestContext,
+ xmlHttp.__dtsRequestMethod,
+ dtsRequestEvent);
}
}
finally
Modified: myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js?view=diff&rev=545348&r1=545347&r2=545348
==============================================================================
--- myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js (original)
+++ myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js Thu Jun 7 16:31:56 2007
@@ -22,7 +22,6 @@
* TrXMLRequest class is a low-level XML HTTP Request
* wrapper
**/
-
/**
* Default constructor. Creates an asynchronous XML HTTP request
**/
Modified: myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js?view=diff&rev=545348&r1=545347&r2=545348
==============================================================================
--- myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js (original)
+++ myfaces/trinidad/branches/awiner-use-XHR-branch/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js Thu Jun 7 16:31:56 2007
@@ -25,12 +25,10 @@
*/
function TrXMLRequestEvent(
status,
- context,
request
)
{
this._status = status;
- this._context = context;
this._request = request;
}
@@ -44,10 +42,6 @@
return this._status;
}
-TrXMLRequestEvent.prototype.getContext = function()
-{
- return this._context;
-}
/**
* Returns the response of the Data Transfer Request as an XML document
* NOTE: this method is valid only for TrXMLRequestEvent.STATUS_COMPLETE