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/04/20 21:19:37 UTC
svn commit: r936035 [2/2] - in /myfaces/trinidad/trunk: ./
trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/
trinidad-examples/trinidad-demo/src/main/webapp/WEB-INF/
trinidad-examples/trinidad-demo/src/main/webapp/component...
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js?rev=936035&r1=936034&r2=936035&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequest.js Tue Apr 20 19:19:36 2010
@@ -34,7 +34,6 @@ function TrXMLRequest()
this.xmlhttp = TrXMLRequest._createXmlHttpRequest();
}
-
/**
* Request state constants. See getCompletionState()
**/
@@ -206,4 +205,124 @@ 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);
+
+ var payload = {
+ "onevent": ajaxCallback,
+ "onerror": ajaxCallback,
+ "Tr-PPR-Message": true // Indicate that this a "legacy" PPR request sent over jsf.ajax
+ };
+
+ for (var p in this._params)
+ {
+ payload[p] = this._params[p];
+ }
+ jsf.ajax.request(
+ source,
+ this._event,
+ payload);
+
+ // 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/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js?rev=936035&r1=936034&r2=936035&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/xhr/XMLRequestEvent.js Tue Apr 20 19:19:36 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
@@ -147,4 +161,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