1 /* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to you under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * @class 19 * @name FormData 20 * @memberOf myfaces._impl.xhrCore.engine 21 * @description 22 * 23 * html5 formdata object emulation for the iframe 24 */ 25 _MF_CLS(_PFX_XHR+"engine.FormData", Object, 26 /** @lends myfaces._impl.xhrCore.engine.FormData.prototype */ 27 { 28 form: null, 29 viewstate: null, 30 _appendedParams: {}, 31 32 constructor_: function(form) { 33 this.form = form; 34 }, 35 36 append: function(key, value) { 37 this._appendedParams[key] = true; 38 if (this.form) { 39 this._appendHiddenValue(key, value); 40 } 41 }, 42 43 _finalize: function() { 44 this._removeAppendedParams(); 45 }, 46 47 _appendHiddenValue: function(key, value) { 48 if ('undefined' == typeof value) { 49 return; 50 } 51 var _Dom = myfaces._impl._util._Dom; 52 var input = _Dom.createElement("input", { 53 "type": "hidden", "name": key, "style": "display:none", "value": value 54 }); 55 56 this.form.appendChild(input); 57 }, 58 59 _removeAppendedParams: function() { 60 if (!this.form) return; 61 for (var cnt = this.form.elements.length - 1; cnt >= 0; cnt--) { 62 var elem = this.form.elements[cnt]; 63 if (this._appendedParams[elem.name] && elem.type == "hidden") { 64 elem.parentNode.removeChild(elem); 65 delete elem; 66 } 67 } 68 this._appendedParams = {}; 69 } 70 71 });