From 46692a6d37aeb8d2a2ccc907236985ad035f3978 Mon Sep 17 00:00:00 2001 From: Werner Punz Date: Fri, 3 Nov 2023 08:52:26 +0100 Subject: [PATCH 1/6] https://issues.apache.org/jira/browse/MYFACES-4606 Fix for MyFaces 4606, checkboxes and radio buttons are not appended automatically if unchecked! --- .../myfaces/_impl/xhrCore/_AjaxUtils.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js index d41b8a457..cf03b3f25 100644 --- a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js +++ b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js @@ -57,11 +57,17 @@ _MF_SINGLTN(_PFX_XHR+"_AjaxUtils", _MF_OBJECT, */ appendIssuingItem: function (item, targetBuf) { // if triggered by a Button send it along - if (item && item.type && - (item.type.toLowerCase() == "submit" || - item.type.toLowerCase() == "button" )) { - //buttons not always have a name unlike inputs - targetBuf.append(item.id || item.name, item.value); + var type = (item || item.type || "").toLowerCase(); + + //MYFACES-4606 we cannot send a value on an unchecked box as issuing element + if(("checkbox" == type || "radio" == type) && !item.checked) { + return; + } else if ("checkbox" == type || "radio" == type) { + var value = ("undefined" == typeof item.value || null == item.value) ? true : item.value; + targetBuf.append(item.id || item.name, value); + } else { + var itemValue = ("undefined" == typeof item.value || null == item.value) ? "" : item.value; + targetBuf.append(item.id || item.name, itemValue); } }, From 72fba7abc70e63d65da2758d8843614508cc1f6f Mon Sep 17 00:00:00 2001 From: Werner Punz Date: Mon, 6 Nov 2023 21:40:01 +0100 Subject: [PATCH 2/6] https://issues.apache.org/jira/browse/MYFACES-4606 Fix for MyFaces 4606, checkboxes and radio buttons are not appended automatically if unchecked! --- .../META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js index cf03b3f25..391972617 100644 --- a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js +++ b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js @@ -57,7 +57,7 @@ _MF_SINGLTN(_PFX_XHR+"_AjaxUtils", _MF_OBJECT, */ appendIssuingItem: function (item, targetBuf) { // if triggered by a Button send it along - var type = (item || item.type || "").toLowerCase(); + var type = ((item && item.type) || "").toLowerCase(); //MYFACES-4606 we cannot send a value on an unchecked box as issuing element if(("checkbox" == type || "radio" == type) && !item.checked) { From 0d69d1204291c6e2fb7ce8f79b9bdeb049777676 Mon Sep 17 00:00:00 2001 From: Werner Punz Date: Mon, 6 Nov 2023 22:45:52 +0100 Subject: [PATCH 3/6] https://issues.apache.org/jira/browse/MYFACES-4606 Fix for MyFaces 4606, checkboxes and radio buttons are not appended automatically if unchecked! --- .../META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js index 391972617..b0016d3da 100644 --- a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js +++ b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js @@ -57,8 +57,13 @@ _MF_SINGLTN(_PFX_XHR+"_AjaxUtils", _MF_OBJECT, */ appendIssuingItem: function (item, targetBuf) { // if triggered by a Button send it along + var identifier = item.id || item.name; var type = ((item && item.type) || "").toLowerCase(); + if(targetBuf.hasKey(identifier)) { //already processed within the values + return; + } + //MYFACES-4606 we cannot send a value on an unchecked box as issuing element if(("checkbox" == type || "radio" == type) && !item.checked) { return; From be1130649cc485e051bf466f4d6a45f2f3315082 Mon Sep 17 00:00:00 2001 From: Werner Punz Date: Tue, 7 Nov 2023 17:01:02 +0100 Subject: [PATCH 4/6] https://issues.apache.org/jira/browse/MYFACES-4606 haskey not properly working --- .../resources/myfaces/_impl/_util/_Lang.js | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js b/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js index e27fd5fb5..cbc5d0a4c 100644 --- a/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js +++ b/api/src/main/javascript/META-INF/resources/myfaces/_impl/_util/_Lang.js @@ -561,10 +561,16 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr //we simulate the dom level 2 form element here var _newCls = null; var bufInstance = null; + var _Lang = this; if (!this.FormDataDecoratorArray) { this.FormDataDecoratorArray = function (theFormData) { this._valBuf = theFormData; this._idx = {}; + var _t = this; + _Lang.arrForEach(theFormData, function(item) { + var key = item[0]; + _t._idx[decodeURIComponent(key)] = true; + }); }; _newCls = this.FormDataDecoratorArray; _newCls.prototype.append = function (key, val) { @@ -583,6 +589,12 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr this._preprocessedData = theFormData; this._valBuf = []; this._idx = {}; + var _t = this; + var keyValuePairs = theFormData.split(/\&/gi); + _Lang.arrForEach(keyValuePairs, function(item) { + var key = _Lang.trim(item.split(/\=/gi)[0]); + _t._idx[decodeURIComponent(key)] = true; + }); }; _newCls = this.FormDataDecoratorString; _newCls.prototype.append = function (key, val) { @@ -591,7 +603,8 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr }; //for now we check only for keys which are added subsequently otherwise we do not perform any checks _newCls.prototype.hasKey = function (key) { - return !!this._idx[key]; + var _t = this; + return !!(this._idx[key]); }; _newCls.prototype.makeFinal = function () { if (this._preprocessedData != "") { @@ -602,9 +615,15 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr }; } if (!this.FormDataDecoratorOther) { + /** + * expected a form data object + * @param theFormData object of type form data or something similar + * @constructor + */ this.FormDataDecoratorOther = function (theFormData) { - this._valBuf = theFormData || []; + this._valBuf = theFormData; this._idx = {}; + }; _newCls = this.FormDataDecoratorOther; _newCls.prototype.append = function (key, val) { @@ -612,7 +631,7 @@ _MF_SINGLTN(_PFX_UTIL + "_Lang", Object, /** @lends myfaces._impl._util._Lang.pr this._idx[key] = true; }; _newCls.prototype.hasKey = function (key) { - return !!this._idx[key]; + return !!(this._idx[key] || this._valBuf.has(key)); }; _newCls.prototype.makeFinal = function () { return this._valBuf; From bf2b5b2b9252ea091229a58f5ee6f9f5837c4902 Mon Sep 17 00:00:00 2001 From: Werner Punz Date: Mon, 13 Nov 2023 16:31:28 +0100 Subject: [PATCH 5/6] https://issues.apache.org/jira/browse/MYFACES-4638: crossport from 4.0 fix --- .../resources/myfaces/_impl/xhrCore/_AjaxUtils.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js index b0016d3da..aae1e8263 100644 --- a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js +++ b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js @@ -65,14 +65,16 @@ _MF_SINGLTN(_PFX_XHR+"_AjaxUtils", _MF_OBJECT, } //MYFACES-4606 we cannot send a value on an unchecked box as issuing element - if(("checkbox" == type || "radio" == type) && !item.checked) { + let isCheckboxRadio = "checkbox" == type || "radio" == type; + if(isCheckboxRadio && !item.checked) { return; - } else if ("checkbox" == type || "radio" == type) { + } else if (isCheckboxRadio) { var value = ("undefined" == typeof item.value || null == item.value) ? true : item.value; - targetBuf.append(item.id || item.name, value); - } else { - var itemValue = ("undefined" == typeof item.value || null == item.value) ? "" : item.value; - targetBuf.append(item.id || item.name, itemValue); + targetBuf.append(identifier, value); + //item must have a valid value to be able to be appended, without it no dice! + } else if(!(("undefined" == typeof item.value) || (null == item.value))) { + var itemValue = item.value; + targetBuf.append(identifier, itemValue); } }, From c98475411d9c415ce57321a6ea3800c26b0e00d2 Mon Sep 17 00:00:00 2001 From: Werner Punz Date: Mon, 13 Nov 2023 16:33:52 +0100 Subject: [PATCH 6/6] https://issues.apache.org/jira/browse/MYFACES-4638: let not allowed --- .../META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js index aae1e8263..006e24cdf 100644 --- a/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js +++ b/api/src/main/javascript/META-INF/resources/myfaces/_impl/xhrCore/_AjaxUtils.js @@ -65,8 +65,8 @@ _MF_SINGLTN(_PFX_XHR+"_AjaxUtils", _MF_OBJECT, } //MYFACES-4606 we cannot send a value on an unchecked box as issuing element - let isCheckboxRadio = "checkbox" == type || "radio" == type; - if(isCheckboxRadio && !item.checked) { + var isCheckboxRadio = "checkbox" == type || "radio" == type; + if(isCheckboxRadio && !item.checked) { return; } else if (isCheckboxRadio) { var value = ("undefined" == typeof item.value || null == item.value) ? true : item.value;