You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2012/12/03 12:22:41 UTC
svn commit: r1416453 - in
/myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl:
core/Impl.js xhrCore/_AjaxRequest.js
Author: werpu
Date: Mon Dec 3 11:22:40 2012
New Revision: 1416453
URL: http://svn.apache.org/viewvc?rev=1416453&view=rev
Log:
updating the window id handling to the latest spec changes
Modified:
myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js
myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
Modified: myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js?rev=1416453&r1=1416452&r2=1416453&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js (original)
+++ myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/core/Impl.js Mon Dec 3 11:22:40 2012
@@ -50,7 +50,7 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
P_PARTIAL_SOURCE:"javax.faces.source",
P_VIEWSTATE:"javax.faces.ViewState",
- P_CLIENTWINDOW: "javax.faces.ClientWindow",
+ P_CLIENTWINDOW:"javax.faces.ClientWindow",
P_AJAX:"javax.faces.partial.ajax",
P_EXECUTE:"javax.faces.partial.execute",
P_RENDER:"javax.faces.partial.render",
@@ -193,8 +193,12 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
onerror:options.onerror,
//TODO move the myfaces part into the _mfInternal part
- myfaces:options.myfaces
+ myfaces:options.myfaces,
+ _mfInternal:{}
};
+ //additional meta information to speed things up, note internal non jsf
+ //pass through options are stored under _mfInternal in the context
+ var mfInternal = context._mfInternal;
/**
* fetch the parent form
@@ -208,23 +212,33 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
this._getForm(elem, event);
/**
- * JSF2.2 client window must be part of the issuing form so it is encoded
- * automatically in the request
- */
+ * JSF2.2 client window must be part of the issuing form so it is encoded
+ * automatically in the request
+ */
//we set the client window before encoding by a call to jsf.getClientWindow
var clientWindow = jsf.getClientWindow(form);
//in case someone decorates the getClientWindow we reset the value from
//what we are getting
- if('undefined' != typeof clientWindow && null != clientWindow) {
+ if ('undefined' != typeof clientWindow && null != clientWindow) {
var formElem = _Dom.getNamedElementFromForm(form, this.P_CLIENTWINDOW);
- if(formElem) {
- //we let the encoding do the
+ if (formElem) {
+ //we store the value for later processing during the ajax phase
//job so that we do not get double values
- formElem.value = clientWindow;
+ context._mfInternal._clientWindow = jsf.getClientWindow(form);
} else {
passThrgh[this.P_CLIENTWINDOW] = jsf.getClientWindow(form);
}
+ } /* spec proposal
+ else {
+ var formElem = _Dom.getNamedElementFromForm(form, this.P_CLIENTWINDOW);
+ if (formElem) {
+ context._mfInternal._clientWindow = "undefined";
+ } else {
+ passThrgh[this.P_CLIENTWINDOW] = "undefined";
+ }
}
+ */
+
/**
* binding contract the javax.faces.source must be set
*/
@@ -265,11 +279,6 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
*/
var transportType = this._getTransportType(context, passThrgh, form);
- //additional meta information to speed things up, note internal non jsf
- //pass through options are stored under _mfInternal in the context
- context._mfInternal = {};
- var mfInternal = context._mfInternal;
-
mfInternal["_mfSourceFormId"] = form.id;
mfInternal["_mfSourceControlId"] = elementId;
mfInternal["_mfTransportType"] = transportType;
@@ -343,19 +352,19 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
var transportAutoSelection = getConfig(context, "transportAutoSelection", true);
/*var isMultipart = (transportAutoSelection && _Dom.getAttribute(form, "enctype") == "multipart/form-data") ?
- _Dom.isMultipartCandidate((!getConfig(context, "pps",false))? form : passThrgh[this.P_EXECUTE]) :
- false;
+ _Dom.isMultipartCandidate((!getConfig(context, "pps",false))? form : passThrgh[this.P_EXECUTE]) :
+ false;
**/
- if(!transportAutoSelection) {
+ if (!transportAutoSelection) {
return getConfig(context, "transportType", "xhrQueuedPost");
}
- var multiPartCandidate = _Dom.isMultipartCandidate((!getConfig(context, "pps",false)) ?
+ var multiPartCandidate = _Dom.isMultipartCandidate((!getConfig(context, "pps", false)) ?
form : passThrgh[this.P_EXECUTE]);
- var multipartForm = (_Dom.getAttribute(form, "enctype") || "").toLowerCase() == "multipart/form-data";
+ var multipartForm = (_Dom.getAttribute(form, "enctype") || "").toLowerCase() == "multipart/form-data";
//spec section jsdoc, if we have a multipart candidate in our execute (aka fileupload)
//and the form is not multipart then we have to raise an error
- if(multiPartCandidate && ! multipartForm) {
- throw _Lang.makeException(new Error(), null, null, this._nameSpace, "_getTransportType", _Lang.getMessage("ERR_NO_MULTIPART_FORM", "No Multipart form", form.id));
+ if (multiPartCandidate && !multipartForm) {
+ throw _Lang.makeException(new Error(), null, null, this._nameSpace, "_getTransportType", _Lang.getMessage("ERR_NO_MULTIPART_FORM", "No Multipart form", form.id));
}
var isMultipart = multiPartCandidate && multipartForm;
/**
@@ -412,8 +421,8 @@ _MF_SINGLTN(_PFX_CORE + "Impl", _MF_OBJE
if (none) {
//in case of none nothing is returned
- if('undefined' != typeof passThrgh.target) {
- delete passThrgh.target;
+ if ('undefined' != typeof passThrgh.target) {
+ delete passThrgh.target;
}
return passThrgh;
}
Modified: myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js?rev=1416453&r1=1416452&r2=1416453&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js (original)
+++ myfaces/core/branches/2.2.x/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxRequest.js Mon Dec 3 11:22:40 2012
@@ -31,18 +31,18 @@
*/
_MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_OBJECT, /** @lends myfaces._impl.xhrCore._AjaxRequest.prototype */ {
- _contentType: "application/x-www-form-urlencoded",
+ _contentType:"application/x-www-form-urlencoded",
/** source element issuing the request */
- _source: null,
+ _source:null,
/** context passed down from the caller */
_context:null,
/** source form issuing the request */
- _sourceForm: null,
+ _sourceForm:null,
/** passthrough parameters */
- _passThrough: null,
+ _passThrough:null,
/** queue control */
- _timeout: null,
+ _timeout:null,
/** enqueuing delay */
//_delay:null,
/** queue size */
@@ -52,13 +52,13 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
back reference to the xhr queue,
only set if the object really is queued
*/
- _xhrQueue: null,
+ _xhrQueue:null,
/** pps an array of identifiers which should be part of the submit, the form is ignored */
- _partialIdsArray : null,
+ _partialIdsArray:null,
/** xhr object, internal param */
- _xhr: null,
+ _xhr:null,
/** predefined method */
_ajaxType:"POST",
@@ -70,8 +70,8 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
*/
_CONTENT_TYPE:"Content-Type",
_HEAD_FACES_REQ:"Faces-Request",
- _VAL_AJAX: "partial/ajax",
- _XHR_CONST: myfaces._impl.xhrCore.engine.XhrConst,
+ _VAL_AJAX:"partial/ajax",
+ _XHR_CONST:myfaces._impl.xhrCore.engine.XhrConst,
// _exception: null,
// _requestParameters: null,
@@ -85,7 +85,7 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
* @param {Object} args an arguments map which an override any of the given protected
* instance variables, by a simple name value pair combination
*/
- constructor_: function(args) {
+ constructor_:function (args) {
try {
this._callSuper("constructor_", args);
@@ -111,27 +111,29 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
/**
* Sends an Ajax request
*/
- send : function() {
+ send:function () {
var _Lang = this._Lang;
var _RT = this._RT;
-
+ var _Dom = this._Dom;
try {
- var scopeThis = _Lang.hitch(this, function(functionName) {
+ var scopeThis = _Lang.hitch(this, function (functionName) {
return _Lang.hitch(this, this[functionName]);
});
this._xhr = _Lang.mixMaps(this._getTransport(), {
- onprogress: scopeThis("onprogress"),
- ontimeout: scopeThis("ontimeout"),
- //remove for xhr level2 support (chrome has problems with it)
+ onprogress:scopeThis("onprogress"),
+ ontimeout:scopeThis("ontimeout"),
+ //remove for xhr level2 support (chrome has problems with it)
//for chrome we have to emulate the onloadend by calling it explicitely
//and leave the onload out
//onloadend: scopeThis("ondone"),
- onload: scopeThis("onsuccess"),
- onerror: scopeThis("onerror")
+ onload:scopeThis("onsuccess"),
+ onerror:scopeThis("onerror")
}, true);
+
+ this._applyClientWindowId();
var xhr = this._xhr,
sourceForm = this._sourceForm,
targetURL = (typeof sourceForm.elements[this.ENCODED_URL] == 'undefined') ?
@@ -140,7 +142,7 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
formData = this.getFormData();
for (var key in this._passThrough) {
- if(!this._passThrough.hasOwnProperty(key)) continue;
+ if (!this._passThrough.hasOwnProperty(key)) continue;
formData.append(key, this._passThrough[key]);
}
@@ -150,14 +152,13 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
xhr.timeout = this._timeout || 0;
-
this._applyContentType(xhr);
xhr.setRequestHeader(this._HEAD_FACES_REQ, this._VAL_AJAX);
//some webkit based mobile browsers do not follow the w3c spec of
// setting the accept headers automatically
- if(this._RT.browser.isWebKit) {
- xhr.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+ if (this._RT.browser.isWebKit) {
+ xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
}
this._sendEvent("BEGIN");
//Check if it is a custom form data object
@@ -169,8 +170,27 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
} catch (e) {
//_onError//_onError
- e = (e._mfInternal)? e: this._Lang.makeException(new Error(), "sendError","sendError", this._nameSpace, "send", e.message);
+ e = (e._mfInternal) ? e : this._Lang.makeException(new Error(), "sendError", "sendError", this._nameSpace, "send", e.message);
this._stdErrorHandler(this._xhr, this._context, e);
+ } finally {
+ this._restoreClientWindowId();
+ }
+ },
+
+ _applyClientWindowId:function () {
+
+ if ('undefined' != typeof this._context._mfInternal._clientWindow) {
+ var clientWindow = this._Dom.getNamedElementFromForm(this._sourceForm, "javax.faces.ClientWindow");
+ this._context._mfInternal._clientWindowOld = clientWindow.value;
+ clientWindow.value = this._context._mfInternal._clientWindow;
+ }
+ },
+
+ _restoreClientWindowId:function () {
+ //we have to reset the client window back to its original state
+ if ('undefined' != typeof this._context._mfInternal._clientWindowOld) {
+ var clientWindow = this._Dom.getNamedElementFromForm(this._sourceForm, "javax.faces.ClientWindow");
+ clientWindow.value = this._context._mfInternal._clientWindow;
}
},
@@ -180,18 +200,16 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
* @param xhr
* @private
*/
- _applyContentType: function(xhr) {
- var contentType = this._contentType+"; charset=utf-8";
+ _applyContentType:function (xhr) {
+ var contentType = this._contentType + "; charset=utf-8";
xhr.setRequestHeader(this._CONTENT_TYPE, contentType);
},
-
- ondone: function() {
- this._requestDone();
+ ondone:function () {
+ this._requestDone();
},
-
- onsuccess: function(/*evt*/) {
+ onsuccess:function (/*evt*/) {
var context = this._context;
var xhr = this._xhr;
@@ -203,19 +221,17 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
context._mfInternal = context._mfInternal || {};
jsf.ajax.response((xhr.getXHRObject) ? xhr.getXHRObject() : xhr, context);
-
-
} catch (e) {
this._stdErrorHandler(this._xhr, this._context, e);
- //add for xhr level2 support
- } finally {
+ //add for xhr level2 support
+ } finally {
//W3C spec onloadend must be called no matter if success or not
this.ondone();
}
},
- onerror: function(/*evt*/) {
+ onerror:function (/*evt*/) {
//TODO improve the error code detection here regarding server errors etc...
//and push it into our general error handling subframework
var context = this._context;
@@ -227,20 +243,20 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
try {
var UNKNOWN = _Lang.getMessage("UNKNOWN");
//status can be 0 and statusText can be ""
- var status = ('undefined' != xhr.status && null != xhr.status)? xhr.status : UNKNOWN;
- var statusText = ('undefined' != xhr.statusText && null != xhr.statusText)? xhr.statusText : UNKNOWN;
- errorText = _Lang.getMessage("ERR_REQU_FAILED", null,status,statusText);
+ var status = ('undefined' != xhr.status && null != xhr.status) ? xhr.status : UNKNOWN;
+ var statusText = ('undefined' != xhr.statusText && null != xhr.statusText) ? xhr.statusText : UNKNOWN;
+ errorText = _Lang.getMessage("ERR_REQU_FAILED", null, status, statusText);
} catch (e) {
errorText = _Lang.getMessage("ERR_REQ_FAILED_UNKNOWN", null);
} finally {
try {
- var _Impl = this.attr("impl");
- _Impl.sendError(xhr, context, _Impl.HTTPERROR,
- _Impl.HTTPERROR, errorText,"","myfaces._impl.xhrCore._AjaxRequest","onerror");
+ var _Impl = this.attr("impl");
+ _Impl.sendError(xhr, context, _Impl.HTTPERROR,
+ _Impl.HTTPERROR, errorText, "", "myfaces._impl.xhrCore._AjaxRequest", "onerror");
} finally {
//add for xhr level2 support
- //since chrome does not call properly the onloadend we have to do it manually
+ //since chrome does not call properly the onloadend we have to do it manually
//to eliminate xhr level1 for the compile profile modern
//W3C spec onloadend must be called no matter if success or not
this.ondone();
@@ -249,11 +265,11 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
//_onError
},
- onprogress: function(/*evt*/) {
+ onprogress:function (/*evt*/) {
//do nothing for now
},
- ontimeout: function(/*evt*/) {
+ ontimeout:function (/*evt*/) {
try {
//we issue an event not an error here before killing the xhr process
this._sendEvent("TIMEOUT_EVENT");
@@ -263,31 +279,29 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
}
},
- _formDataToURI: function(formData) {
+ _formDataToURI:function (formData) {
if (formData && formData.makeFinal) {
formData = formData.makeFinal()
}
return formData;
},
- _getTransport: function() {
+ _getTransport:function () {
var xhr = this._RT.getXHRObject();
//the current xhr level2 timeout w3c spec is not implemented by the browsers yet
//we have to do a fallback to our custom routines
//add for xhr level2 support
- //Chrome fails in the current builds, on our loadend, we disable the xhr
+ //Chrome fails in the current builds, on our loadend, we disable the xhr
//level2 optimisations for now
if (/*('undefined' == typeof this._timeout || null == this._timeout) &&*/ this._RT.getXHRLvl() >= 2) {
//no timeout we can skip the emulation layer
return xhr;
}
- return new myfaces._impl.xhrCore.engine.Xhr1({xhrObject: xhr});
+ return new myfaces._impl.xhrCore.engine.Xhr1({xhrObject:xhr});
},
-
-
//----------------- backported from the base request --------------------------------
//non abstract ones
/**
@@ -299,7 +313,7 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
* @return an element of formDataWrapper
* which keeps the final Send Representation of the
*/
- getFormData : function() {
+ getFormData:function () {
var _AJAXUTIL = this._AJAXUTIL, myfacesOptions = this._context.myfaces;
return this._Lang.createFormDataDecorator(jsf.getViewState(this._sourceForm));
},
@@ -314,10 +328,10 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
* @param context the context holding all values for further processing
* @param exception the embedded exception
*/
- _stdErrorHandler: function(request, context, exception) {
+ _stdErrorHandler:function (request, context, exception) {
var xhrQueue = this._xhrQueue;
try {
- this.attr("impl").stdErrorHandler(request, context, exception);
+ this.attr("impl").stdErrorHandler(request, context, exception);
} finally {
if (xhrQueue) {
xhrQueue.cleanup();
@@ -325,12 +339,12 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
}
},
- _sendEvent: function(evtType) {
+ _sendEvent:function (evtType) {
var _Impl = this.attr("impl");
_Impl.sendEvent(this._xhr, this._context, _Impl[evtType]);
},
- _requestDone: function() {
+ _requestDone:function () {
var queue = this._xhrQueue;
if (queue) {
queue.processQueue();
@@ -341,7 +355,7 @@ _MF_CLS(_PFX_XHR + "_AjaxRequest", _MF_O
},
//cleanup
- _finalize: function() {
+ _finalize:function () {
if (this._xhr.readyState == this._XHR_CONST.READY_STATE_DONE) {
this._callSuper("_finalize");
}