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 2023/11/21 20:31:19 UTC

(myfaces) branch 2.3.x updated: Apply complete MYFACES-4606 fix

This is an automated email from the ASF dual-hosted git repository.

werpu pushed a commit to branch 2.3.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.3.x by this push:
     new e2dec4a02 Apply complete MYFACES-4606 fix
     new 2bc051b79 Merge pull request #646 from volosied/4606-23x
e2dec4a02 is described below

commit e2dec4a02ba7a0f3acc9a8e4d3ff0a78781c29d9
Author: Volodymyr Siedlecki <vo...@gmail.com>
AuthorDate: Fri Nov 17 12:52:59 2023 -0500

    Apply complete MYFACES-4606 fix
---
 .../resources/myfaces/_impl/_util/_Lang.js         | 23 ++++++++++++++++++++--
 .../resources/myfaces/_impl/xhrCore/_AjaxUtils.js  | 23 +++++++++++++++++-----
 2 files changed, 39 insertions(+), 7 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..87e4e1d09 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._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;
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 252100485..5d0da4fea 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
@@ -60,11 +60,24 @@ _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 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
+        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;
+            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);
         }
     },