Merge pull request #647 from volosied/4606-22x

Apply updated  MYFACES-4606 fix
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 32e9306..721aa26 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
@@ -543,10 +543,16 @@
         //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) {
@@ -565,6 +571,12 @@
                 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) {
@@ -573,7 +585,8 @@
             };
             //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 != "") {
@@ -584,17 +597,23 @@
             };
         }
         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) {
-                this._valBuf.append(key, val);
+                this._valBuf.push([encodeURIComponent(key), encodeURIComponent(val)]);
                 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 d41b8a4..006e24c 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,24 @@
      */
     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);
         }
     },