jsf.js_next_gen 4.0.0-RC.3 → 4.0.0-RC.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/dist/docs/assets/main.js +56 -52
  2. package/dist/docs/assets/style.css +23 -0
  3. package/dist/window/faces-development.js +2961 -3011
  4. package/dist/window/faces-development.js.br +0 -0
  5. package/dist/window/faces-development.js.gz +0 -0
  6. package/dist/window/faces-development.js.map +1 -1
  7. package/dist/window/faces.js +1 -1
  8. package/dist/window/faces.js.LICENSE.txt +0 -2
  9. package/dist/window/faces.js.br +0 -0
  10. package/dist/window/faces.js.gz +0 -0
  11. package/dist/window/faces.js.map +1 -1
  12. package/dist/window/jsf-development.js +2966 -3016
  13. package/dist/window/jsf-development.js.br +0 -0
  14. package/dist/window/jsf-development.js.gz +0 -0
  15. package/dist/window/jsf-development.js.map +1 -1
  16. package/dist/window/jsf.js +1 -1
  17. package/dist/window/jsf.js.LICENSE.txt +0 -2
  18. package/dist/window/jsf.js.br +0 -0
  19. package/dist/window/jsf.js.gz +0 -0
  20. package/dist/window/jsf.js.map +1 -1
  21. package/package.json +16 -16
  22. package/src/main/test.xml +23 -0
  23. package/src/main/typescript/@types/definitions/index.d.ts +12 -7
  24. package/src/main/typescript/api/_api.ts +4 -3
  25. package/src/main/typescript/impl/AjaxImpl.ts +125 -41
  26. package/src/main/typescript/impl/core/Const.ts +52 -41
  27. package/src/main/typescript/impl/util/Assertions.ts +16 -8
  28. package/src/main/typescript/impl/util/ExtDomQuery.ts +12 -4
  29. package/src/main/typescript/impl/util/FileUtils.ts +66 -0
  30. package/src/main/typescript/impl/util/HiddenInputBuilder.ts +89 -0
  31. package/src/main/typescript/impl/util/Lang.ts +9 -11
  32. package/src/main/typescript/impl/xhrCore/ErrorData.ts +15 -10
  33. package/src/main/typescript/impl/xhrCore/EventData.ts +2 -2
  34. package/src/main/typescript/impl/xhrCore/IResponseProcessor.ts +15 -1
  35. package/src/main/typescript/impl/xhrCore/RequestDataResolver.ts +69 -24
  36. package/src/main/typescript/impl/xhrCore/ResonseDataResolver.ts +4 -4
  37. package/src/main/typescript/impl/xhrCore/Response.ts +55 -38
  38. package/src/main/typescript/impl/xhrCore/ResponseProcessor.ts +173 -98
  39. package/src/main/typescript/impl/xhrCore/XhrFormData.ts +91 -168
  40. package/src/main/typescript/impl/xhrCore/XhrRequest.ts +39 -23
  41. package/src/main/typescript/myfaces/OamSubmit.ts +29 -13
  42. package/src/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.ts +1 -1
  43. package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +73 -1
  44. package/src/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.ts +40 -1
  45. package/src/main/typescript/test/impl/ImplTest.spec.ts +3 -3
  46. package/src/main/typescript/test/impl/ImplTest_23.spec.ts +3 -3
  47. package/src/main/typescript/test/xhrCore/EventTests.spec.ts +1 -1
  48. package/src/main/typescript/test/xhrCore/FileUploadTest.spec.ts +5 -2
  49. package/src/main/typescript/test/xhrCore/NamespacesRequestTest.spec.ts +203 -0
  50. package/src/main/typescript/test/xhrCore/OamSubmitTest.spec.ts +177 -0
  51. package/src/main/typescript/test/xhrCore/RequestParamsTest.spec.ts +158 -17
  52. package/src/main/typescript/test/xhrCore/RequestTest.spec.ts +70 -3
  53. package/src/main/typescript/test/xhrCore/RequestTest_23.spec.ts +39 -3
  54. package/src/main/typescript/test/xhrCore/ResponseTest.spec.ts +372 -34
  55. package/src/main/typescript/test/xhrCore/ResponseTest23.spec.ts +43 -9
  56. package/src/main/typescript/test/xhrCore/XhrFormDataTest.spec.ts +67 -49
  57. package/src/main/typescript/test.xml +6 -0
  58. package/src/main/typescript/tsconfig.json +2 -2
  59. package/src/test/resources/jsf-development.js +1 -1
  60. package/src/tmp/test.html +12 -88
  61. package/target/api/_api.js +16 -29
  62. package/target/api/_api.js.map +1 -1
  63. package/target/api/faces.js +4 -4
  64. package/target/api/faces.js.map +1 -1
  65. package/target/api/jsf.js +9 -9
  66. package/target/api/jsf.js.map +1 -1
  67. package/target/classes/com/example/jsfs_js_ts/DecoratedFacesJS.class +0 -0
  68. package/target/classes/com/example/jsfs_js_ts/DecoratingResourceHandlerWrapper.class +0 -0
  69. package/target/classes/com/example/jsfs_js_ts/FacesJSMapFileResourceWrapper.class +0 -0
  70. package/target/classes/com/example/jsfs_js_ts/FacesJSMappingDecorator.class +0 -0
  71. package/target/impl/AjaxImpl.js +155 -89
  72. package/target/impl/AjaxImpl.js.map +1 -1
  73. package/target/impl/PushImpl.js +45 -48
  74. package/target/impl/PushImpl.js.map +1 -1
  75. package/target/impl/core/Const.js +52 -40
  76. package/target/impl/core/Const.js.map +1 -1
  77. package/target/impl/core/Context.js +10 -0
  78. package/target/impl/core/Context.js.map +1 -0
  79. package/target/impl/core/ImplTypes.js +9 -14
  80. package/target/impl/core/ImplTypes.js.map +1 -1
  81. package/target/impl/i18n/Messages.js +3 -4
  82. package/target/impl/i18n/Messages.js.map +1 -1
  83. package/target/impl/util/Assertions.js +20 -24
  84. package/target/impl/util/Assertions.js.map +1 -1
  85. package/target/impl/util/AsyncQueue.js +28 -36
  86. package/target/impl/util/AsyncQueue.js.map +1 -1
  87. package/target/impl/util/ExtDomQuery.js +153 -221
  88. package/target/impl/util/ExtDomQuery.js.map +1 -1
  89. package/target/impl/util/FileUtils.js +64 -0
  90. package/target/impl/util/FileUtils.js.map +1 -0
  91. package/target/impl/util/HiddenElementBuilder.js +7 -0
  92. package/target/impl/util/HiddenElementBuilder.js.map +1 -0
  93. package/target/impl/util/HiddenInputBuilder.js +79 -0
  94. package/target/impl/util/HiddenInputBuilder.js.map +1 -0
  95. package/target/impl/util/Lang.js +23 -32
  96. package/target/impl/util/Lang.js.map +1 -1
  97. package/target/impl/util/URLCodec.js +77 -0
  98. package/target/impl/util/URLCodec.js.map +1 -0
  99. package/target/impl/xhrCore/ErrorData.js +41 -64
  100. package/target/impl/xhrCore/ErrorData.js.map +1 -1
  101. package/target/impl/xhrCore/EventData.js +10 -13
  102. package/target/impl/xhrCore/EventData.js.map +1 -1
  103. package/target/impl/xhrCore/RequestContext.js +11 -0
  104. package/target/impl/xhrCore/RequestContext.js.map +1 -0
  105. package/target/impl/xhrCore/RequestDataResolver.js +71 -27
  106. package/target/impl/xhrCore/RequestDataResolver.js.map +1 -1
  107. package/target/impl/xhrCore/ResonseDataResolver.js +16 -16
  108. package/target/impl/xhrCore/ResonseDataResolver.js.map +1 -1
  109. package/target/impl/xhrCore/Response.js +43 -28
  110. package/target/impl/xhrCore/Response.js.map +1 -1
  111. package/target/impl/xhrCore/ResponseProcessor.js +217 -162
  112. package/target/impl/xhrCore/ResponseProcessor.js.map +1 -1
  113. package/target/impl/xhrCore/XhrFormData.js +92 -208
  114. package/target/impl/xhrCore/XhrFormData.js.map +1 -1
  115. package/target/impl/xhrCore/XhrRequest.js +104 -104
  116. package/target/impl/xhrCore/XhrRequest.js.map +1 -1
  117. package/target/myfaces/OamSubmit.js +33 -24
  118. package/target/myfaces/OamSubmit.js.map +1 -1
  119. package/target/test/frameworkBase/LangTest.spec.js +46 -32
  120. package/target/test/frameworkBase/LangTest.spec.js.map +1 -1
  121. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js +238 -228
  122. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js.map +1 -1
  123. package/target/test/frameworkBase/_ext/monadish/LangTest.spec.js +45 -31
  124. package/target/test/frameworkBase/_ext/monadish/LangTest.spec.js.map +1 -1
  125. package/target/test/frameworkBase/_ext/monadish/MappingProbes.js +24 -33
  126. package/target/test/frameworkBase/_ext/monadish/MappingProbes.js.map +1 -1
  127. package/target/test/frameworkBase/_ext/monadish/MappingTest.spec.js +8 -8
  128. package/target/test/frameworkBase/_ext/monadish/MappingTest.spec.js.map +1 -1
  129. package/target/test/frameworkBase/_ext/monadish/MonadTest.spec.js +31 -31
  130. package/target/test/frameworkBase/_ext/monadish/MonadTest.spec.js.map +1 -1
  131. package/target/test/frameworkBase/_ext/monadish/StreamTest.spec.js +50 -48
  132. package/target/test/frameworkBase/_ext/monadish/StreamTest.spec.js.map +1 -1
  133. package/target/test/frameworkBase/_ext/shared/StandardInits.js +310 -132
  134. package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
  135. package/target/test/frameworkBase/_ext/shared/XmlResponses.js +235 -22
  136. package/target/test/frameworkBase/_ext/shared/XmlResponses.js.map +1 -1
  137. package/target/test/impl/ImplTest.spec.js +32 -59
  138. package/target/test/impl/ImplTest.spec.js.map +1 -1
  139. package/target/test/impl/ImplTest_23.spec.js +32 -59
  140. package/target/test/impl/ImplTest_23.spec.js.map +1 -1
  141. package/target/test/impl/SeparatorCharsTest.spec.js +17 -17
  142. package/target/test/impl/SeparatorCharsTest.spec.js.map +1 -1
  143. package/target/test/myfaces/OamSubmit.spec.js +25 -25
  144. package/target/test/myfaces/OamSubmit.spec.js.map +1 -1
  145. package/target/test/queue/AsynchronousProbe.js +23 -29
  146. package/target/test/queue/AsynchronousProbe.js.map +1 -1
  147. package/target/test/queue/AsynchronousQueueTest.spec.js +39 -70
  148. package/target/test/queue/AsynchronousQueueTest.spec.js.map +1 -1
  149. package/target/test/xhrCore/EventTests.spec.js +43 -74
  150. package/target/test/xhrCore/EventTests.spec.js.map +1 -1
  151. package/target/test/xhrCore/FakeWebsocket.js +14 -16
  152. package/target/test/xhrCore/FakeWebsocket.js.map +1 -1
  153. package/target/test/xhrCore/FileUploadTest.spec.js +48 -78
  154. package/target/test/xhrCore/FileUploadTest.spec.js.map +1 -1
  155. package/target/test/xhrCore/NamespacesRequestTest.spec.js +204 -0
  156. package/target/test/xhrCore/NamespacesRequestTest.spec.js.map +1 -0
  157. package/target/test/xhrCore/OamSubmitTest.spec.js +180 -0
  158. package/target/test/xhrCore/OamSubmitTest.spec.js.map +1 -0
  159. package/target/test/xhrCore/RequestParamsTest.spec.js +174 -73
  160. package/target/test/xhrCore/RequestParamsTest.spec.js.map +1 -1
  161. package/target/test/xhrCore/RequestTest.spec.js +173 -149
  162. package/target/test/xhrCore/RequestTest.spec.js.map +1 -1
  163. package/target/test/xhrCore/RequestTest_23.spec.js +127 -142
  164. package/target/test/xhrCore/RequestTest_23.spec.js.map +1 -1
  165. package/target/test/xhrCore/ResponseTest.spec.js +415 -100
  166. package/target/test/xhrCore/ResponseTest.spec.js.map +1 -1
  167. package/target/test/xhrCore/ResponseTest23.spec.js +152 -91
  168. package/target/test/xhrCore/ResponseTest23.spec.js.map +1 -1
  169. package/target/test/xhrCore/ShadowDomTest.spec.js +30 -61
  170. package/target/test/xhrCore/ShadowDomTest.spec.js.map +1 -1
  171. package/target/test/xhrCore/WebsocketTest.js +60 -93
  172. package/target/test/xhrCore/WebsocketTest.js.map +1 -1
  173. package/target/test/xhrCore/XhrFormDataTest.spec.js +79 -30
  174. package/target/test/xhrCore/XhrFormDataTest.spec.js.map +1 -1
  175. package/target/test-classes/.gz +0 -0
  176. package/target/test-classes/com/example/jsfs_js_ts/JsfsJsTsApplicationTests.class +0 -0
  177. package/target/test-classes/fileuploadtest.html +24 -0
  178. package/target/test-classes/jsf-development.js +3559 -0
  179. package/target/test-classes/jsf-development.js.br +0 -0
  180. package/target/test-classes/jsf-development.js.gz +0 -0
  181. package/target/test-classes/jsf-development.js.map +1 -0
  182. package/target/test-classes/jsf.js +3 -0
  183. package/target/test-classes/jsf.js.br +0 -0
  184. package/target/test-classes/jsf.js.gz +0 -0
  185. package/tmp.xml +36 -0
@@ -13,12 +13,20 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import {ArrayCollector, Config, DQ, Lang, LazyStream, Stream} from "mona-dish";
17
- import {EMPTY_STR, IDENT_ALL, IDENT_FORM, P_VIEWSTATE} from "../core/Const";
18
- import isString = Lang.isString;
19
- import {ExtConfig, ExtDomQuery} from "../util/ExtDomQuery";
16
+ import {ArrayCollector, Config, DQ, Stream} from "mona-dish";
17
+ import {$faces, $nsp, EMPTY_STR, IDENT_ALL, IDENT_FORM, IDENT_NONE, P_VIEWSTATE} from "../core/Const";
18
+ import {ExtConfig} from "../util/ExtDomQuery";
19
+ import {
20
+ decodeEncodedValues,
21
+ encodeFormData,
22
+ resolveFiles,
23
+ fixKeyWithoutVal
24
+ } from "../util/FileUtils";
20
25
 
21
26
 
27
+ type ParamsMapper<V, K> = (key: V, item: K) => [V, K];
28
+ const defaultParamsMapper: ParamsMapper<string, any> = (key, item) => [key, item];
29
+
22
30
  /**
23
31
  * A unified form data class
24
32
  * which builds upon our configuration.
@@ -29,7 +37,11 @@ import {ExtConfig, ExtDomQuery} from "../util/ExtDomQuery";
29
37
  *
30
38
  * probably only one needed and one overlay!
31
39
  * the entire file input storing probably is redundant now
32
- * that dom query has been fixed //TODO check this
40
+ * that dom query has been fixed
41
+ *
42
+ * internal storage format
43
+ * every value is stored as an array
44
+ * even scalar ones!
33
45
  */
34
46
  export class XhrFormData extends Config {
35
47
  /**
@@ -45,31 +57,22 @@ export class XhrFormData extends Config {
45
57
  * data collector from a given form
46
58
  *
47
59
  * @param dataSource either a form as DomQuery object or an encoded url string
48
- * @param viewState the form view state or an external viewState coming in as string
60
+ * @param paramsMapper a remapper for the params keys and values
49
61
  * @param executes the executes id list for the elements to being processed
50
62
  * @param partialIds partial ids to collect, to reduce the data sent down
51
63
  */
52
- constructor(private dataSource: DQ | string, viewState?: string, executes?: string[], private partialIds?: string[]) {
64
+ constructor(private dataSource: DQ, private paramsMapper: ParamsMapper<string, any> = defaultParamsMapper, executes?: string[], private partialIds?: string[]) {
53
65
  super({});
54
- //a call to getViewState before must pass the encoded line
55
- //a call from getViewState passes the form element as datasource,
56
- //so we have two call points
57
- // atm we basically encode twice, to keep the code leaner
58
- // this will be later optmized, practically elements
59
- // which are already covered by an external viewstate do not need
60
- // the encoding a second time, because they are overwritten by the viewstate again
61
- if (isString(dataSource)) {
62
- this.assignEncodedString(<string>this.dataSource);
63
- } else {
64
- this.applyFormDataToConfig();
65
- }
66
- //now assign the external viewstate overrides
67
- if ('undefined' != typeof viewState) {
68
- this.assignEncodedString(viewState)
69
- }
70
- if (executes) {
71
- this.postInit(...executes);
72
- }
66
+ //encode and append the issuing item if not a partial ids array of ids is passed
67
+ /*
68
+ * Spec. 13.3.1
69
+ * Collect and encode input elements.
70
+ * Additionally the hidden element jakarta.faces.ViewState
71
+ * Enhancement partial page submit
72
+ */
73
+ this.resolveRequestType(this.dataSource, executes);
74
+ this.encodeSubmittableFields(this.dataSource, this.partialIds);
75
+ this.applyViewState(this.dataSource);
73
76
  }
74
77
 
75
78
  /**
@@ -77,30 +80,11 @@ export class XhrFormData extends Config {
77
80
  * @param executes the executable dom nodes which need to be processed into the form data, which we can send
78
81
  * in our ajax request
79
82
  */
80
- postInit(...executes: Array<string>) {
81
- let fetchFileInputs = (id: string): DQ => {
82
- const INPUT_FILE = "input[type='file']";
83
- if (id == IDENT_ALL) {
84
- return DQ.querySelectorAllDeep(INPUT_FILE);
85
- } else if (id == IDENT_FORM) {
86
- return (<DQ>this.dataSource).matchesSelector(INPUT_FILE) ?
87
- (<DQ>this.dataSource) :
88
- (<DQ>this.dataSource).querySelectorAllDeep(INPUT_FILE);
89
- } else {
90
- let element = DQ.byId(id, true);
91
- return element.matchesSelector(INPUT_FILE) ? element : this.getFileInputs(element);
92
- }
93
- };
94
-
95
- let inputExists = (item: DQ) => {
96
- return item.isPresent();
97
- };
98
-
99
-
100
- this.isMultipartRequest = LazyStream.of(...executes)
101
- .map(fetchFileInputs)
102
- .filter(inputExists)
103
- .first().isPresent();
83
+ resolveRequestType(rootElement: DQ, executes?: Array<string>) {
84
+ if (!executes || executes.indexOf(IDENT_NONE) != -1) {
85
+ return;
86
+ }
87
+ this.isMultipartRequest = rootElement.isMultipartCandidate(true);
104
88
  }
105
89
 
106
90
  /**
@@ -109,124 +93,62 @@ export class XhrFormData extends Config {
109
93
  * @param form the form holding the view state value
110
94
  */
111
95
  private applyViewState(form: DQ) {
112
- let viewState = form.byId(P_VIEWSTATE, true).inputValue;
113
- this.appendIf(viewState.isPresent(), P_VIEWSTATE).value = viewState.value;
96
+ if (this.getIf($nsp(P_VIEWSTATE)).isPresent()) {
97
+ return;
98
+ }
99
+ let viewStateElement = form.querySelectorAllDeep(`[name*='${$nsp(P_VIEWSTATE)}'`);
100
+ let viewState = viewStateElement.inputValue;
101
+ this.appendIf(viewState.isPresent(), this.remapKeyForNamingContainer(viewStateElement.name.value)).value = viewState.value;
114
102
  }
115
103
 
116
- /**
117
- * assigns an url encoded string to this xhrFormData object
118
- * as key value entry
119
- * @param encoded
120
- */
121
- assignEncodedString(encoded: string) {
122
- // this code filters out empty strings as key value pairs
123
- let keyValueEntries = decodeURIComponent(encoded).split(/&/gi)
124
- .filter(item => !!(item || '')
125
- .replace(/\s+/g, ''));
126
- this.assignString(keyValueEntries);
127
- }
128
104
 
129
105
  /**
130
- * assign a set of key value pairs passed as array ['key=val1', 'key2=val2']
131
- * @param keyValueEntries
106
+ * @returns a Form data representation, this is needed for file submits
132
107
  */
133
- assignString(keyValueEntries: string[]) {
134
- let toMerge = new ExtConfig({});
108
+ toFormData(): FormData {
109
+ let ret: any = new FormData();
135
110
 
136
- function splitToKeyVal(line: string) {
137
- return line.split(/=(.*)/gi);
138
- }
111
+ /*
112
+ * expands key: [item1, item2]
113
+ * to: [{key: item1}, {key, item2}]
114
+ */
115
+ let expandArrayedData = ([key, item]) =>
116
+ Stream.of(...(item as Array<any>)).map(item => {
117
+ return {key, item};
118
+ });
139
119
 
140
- function fixKeyWithoutVal(keyVal: string[]) {
141
- return keyVal.length < 3 ? [keyVal?.[0] ?? [], keyVal?.[1] ?? []] : keyVal;
142
- }
120
+ /*
121
+ * remaps the incoming {key, value} tuples
122
+ * to naming container prefixed keys and values
123
+ */
124
+ let remapForNamingContainer = ({key, item}) => {
125
+ key = this.remapKeyForNamingContainer(key);
126
+ return {key, item}
127
+ };
143
128
 
144
- //TODO fix files...
145
- Stream.of(...keyValueEntries)
146
- .map(line => splitToKeyVal(line))
147
- //special case of having keys without values
148
- .map(keyVal => fixKeyWithoutVal(keyVal))
149
- .each(keyVal => {
150
- toMerge.append(keyVal[0] as string).value = keyVal?.splice(1)?.join("") ?? "";
151
- });
152
- //merge with overwrite but no append! (aka no double entries are allowed)
153
- this.shallowMerge(toMerge);
154
- }
129
+ /*
130
+ * collects everything into a FormData object
131
+ */
132
+ let collectFormData = ({key, item}) => {
133
+ ret.append(key, item)
134
+ };
155
135
 
156
- /**
157
- * @returns a Form data representation, this is needed for file submits
158
- */
159
- toFormData(): FormData {
160
- let ret: any = new FormData();
161
- this.appendInputs(ret);
136
+ Stream.ofAssoc(this.value)
137
+ .flatMap(expandArrayedData)
138
+ .map(remapForNamingContainer)
139
+ .each(collectFormData)
162
140
  return ret;
163
141
  }
164
142
 
165
- resolveSubmitIdentifier(elem: HTMLInputElement) {
166
- let identifier = elem.name;
167
- identifier = ((elem?.name ?? "").replace(/s+/gi, "") == "") ? elem.id : identifier;
168
- return identifier;
169
- }
170
-
171
143
  /**
172
144
  * returns an encoded string representation of our xhr form data
173
145
  *
174
146
  * @param defaultStr optional default value if nothing is there to encode
175
147
  */
176
148
  toString(defaultStr = EMPTY_STR): string {
177
- if (this.isAbsent()) {
178
- return defaultStr;
179
- }
180
- let entries = LazyStream.of(...Object.keys(this.value))
181
- .filter(key => this.value.hasOwnProperty(key))
182
- .flatMap(key => Stream.of(...this.value[key]).map(val => [key, val])
183
- //we cannot encode file elements that is handled by multipart requests anyway
184
- .filter(([, value]) => !(value instanceof ExtDomQuery.global().File))
185
- .collect(new ArrayCollector()))
186
-
187
- .map(keyVal => {
188
- return `${encodeURIComponent(keyVal[0])}=${encodeURIComponent(keyVal[1])}`;
189
- })
190
- .collect(new ArrayCollector());
191
-
192
- return entries.join("&")
193
- }
194
-
195
- /**
196
- * helper to fetch all file inputs from as given root element
197
- * @param rootElement
198
- * @private
199
- */
200
- private getFileInputs(rootElement: DQ): DQ {
201
- const rootFileInputs = rootElement
202
- .filter(elem => elem.matchesSelector("input[type='file']"))
203
- const childFileInputs = rootElement
204
- .querySelectorAll("input[type='file']");
205
-
206
- return rootFileInputs.concat(childFileInputs);
149
+ return encodeFormData(this, this.paramsMapper, defaultStr);
207
150
  }
208
151
 
209
- /**
210
- * encode the given fields and apply the view state
211
- * @private
212
- */
213
- private applyFormDataToConfig() {
214
- //encode and append the issuing item if not a partial ids array of ids is passed
215
- /*
216
- * Spec. 13.3.1
217
- * Collect and encode input elements.
218
- * Additionally the hidden element jakarta.faces.ViewState
219
- * Enhancement partial page submit
220
- *
221
- */
222
- this.encodeSubmittableFields(this, <DQ>this.dataSource, this.partialIds);
223
-
224
- if (this.getIf(P_VIEWSTATE).isPresent()) {
225
- return;
226
- }
227
-
228
- this.applyViewState(<DQ>this.dataSource);
229
- }
230
152
 
231
153
  /**
232
154
  * determines fields to submit
@@ -234,28 +156,29 @@ export class XhrFormData extends Config {
234
156
  * @param {Node} parentItem - form element item is nested in
235
157
  * @param {Array} partialIds - ids fo PPS
236
158
  */
237
- private encodeSubmittableFields(targetBuf: Config,
238
- parentItem: DQ, partialIds ?: string[]) {
239
- let toEncode = null;
240
- if (this.partialIds && this.partialIds.length) {
241
- // in case of our myfaces reduced ppr we
242
- // only submit the partials
243
- this._value = {};
244
- toEncode = new DQ(...this.partialIds);
245
-
246
- } else {
247
- if (parentItem.isAbsent()) throw 'NO_PAR_ITEM';
248
- toEncode = parentItem;
249
- }
159
+ public encodeSubmittableFields(parentItem: DQ, partialIds ?: string[]) {
160
+ //encoded String
161
+ const viewStateStr = $faces().getViewState(parentItem.getAsElem(0).value);
162
+
163
+ // we now need to decode it and then merge it into the target buf
164
+ // which hosts already our overrides (aka do not override what is already there(
165
+ // after that we need to deal with form elements on a separate level
166
+ const keyValueEntries: Stream<string[] | [string, File]> = decodeEncodedValues(viewStateStr);
167
+ const fileEntries = resolveFiles(parentItem);
168
+ const concatted = keyValueEntries.concat(fileEntries as any)
169
+ const formData = new ExtConfig({});
170
+
171
+ concatted
172
+ .map(fixKeyWithoutVal)
173
+ .map(keyVal => this.paramsMapper(keyVal[0] as string, keyVal[1]))
174
+ .each((entry) => {
175
+ formData.append(entry[0]).value = entry[1];
176
+ });
250
177
 
251
- //lets encode the form elements
252
- this.shallowMerge(toEncode.deepElements.encodeFormElement());
178
+ this.shallowMerge(formData, true, true);
253
179
  }
254
180
 
255
- private appendInputs(ret: any) {
256
- Stream.of(...Object.keys(this.value))
257
- .each(key => {
258
- Stream.of(...this.value[key]).each(item => ret.append(key, item));
259
- });
181
+ private remapKeyForNamingContainer(key: string): string {
182
+ return this.paramsMapper(key, "")[0];
260
183
  }
261
184
  }
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import {AsyncRunnable} from "../util/AsyncRunnable";
18
- import {Config, DQ, Stream} from "mona-dish";
18
+ import {Config, DQ, DQ$, Stream} from "mona-dish";
19
19
  import {Implementation} from "../AjaxImpl";
20
20
 
21
21
  import {XhrFormData} from "./XhrFormData";
@@ -23,27 +23,35 @@ import {ErrorData} from "./ErrorData";
23
23
  import {EventData} from "./EventData";
24
24
  import {ExtLang} from "../util/Lang";
25
25
  import {
26
+ $faces, $nsp,
26
27
  BEGIN,
27
28
  COMPLETE,
28
29
  CONTENT_TYPE,
29
30
  CTX_PARAM_MF_INTERNAL,
30
- CTX_PARAM_PASS_THR,
31
+ CTX_PARAM_REQ_PASS_THR,
31
32
  ERROR,
32
33
  HEAD_FACES_REQ,
33
- MALFORMEDXML,
34
+ MALFORMEDXML, NAMED_VIEWROOT,
34
35
  NO_TIMEOUT,
35
36
  ON_ERROR,
36
- ON_EVENT, P_EXECUTE,
37
+ ON_EVENT, P_EXECUTE, P_PARTIAL_SOURCE, P_VIEWSTATE, NAMING_CONTAINER_ID,
37
38
  REQ_ACCEPT,
38
39
  REQ_TYPE_GET,
39
- REQ_TYPE_POST,
40
+ REQ_TYPE_POST, SOURCE,
40
41
  STATE_EVT_TIMEOUT,
41
42
  STD_ACCEPT,
42
43
  URL_ENCODED,
43
- VAL_AJAX
44
+ VAL_AJAX, IDENT_NONE
44
45
  } from "../core/Const";
45
- import {resolveFinalUrl, resolveHandlerFunc} from "./RequestDataResolver";
46
+ import {
47
+ resolveFinalUrl,
48
+ resolveHandlerFunc,
49
+ resolveViewRootId,
50
+ resoveNamingContainerMapper
51
+ } from "./RequestDataResolver";
46
52
  import failSaveExecute = ExtLang.failSaveExecute;
53
+ import {ExtConfig} from "../util/ExtDomQuery";
54
+ import {ResponseProcessor} from "./ResponseProcessor";
47
55
 
48
56
  /**
49
57
  * Faces XHR Request Wrapper
@@ -53,6 +61,7 @@ import failSaveExecute = ExtLang.failSaveExecute;
53
61
  * a single ajax request into our queue
54
62
  * and let the queue do the processing.
55
63
  *
64
+ *
56
65
  */
57
66
 
58
67
  export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
@@ -86,7 +95,7 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
86
95
  constructor(
87
96
  private source: DQ,
88
97
  private sourceForm: DQ,
89
- private requestContext: Config,
98
+ private requestContext: ExtConfig,
90
99
  private internalContext: Config,
91
100
  private partialIdsArray = [],
92
101
  private timeout = NO_TIMEOUT,
@@ -111,12 +120,10 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
111
120
  let xhrObject = this.xhrObject;
112
121
 
113
122
  let executesArr = () => {
114
- return this.requestContext.getIf(CTX_PARAM_PASS_THR, P_EXECUTE).get("none").value.split(/\s+/gi);
123
+ return this.requestContext.getIf(CTX_PARAM_REQ_PASS_THR, P_EXECUTE).get(IDENT_NONE).value.split(/\s+/gi);
115
124
  };
116
- try {
117
125
 
118
- let formElement = this.sourceForm.getAsElem(0).value;
119
- let viewState = (window?.faces ?? window?.jsf).getViewState(formElement);
126
+ try {
120
127
  // encoded we need to decode
121
128
  // We generated a base representation of the current form
122
129
  // in case someone has overloaded the viewState with additional decorators we merge
@@ -125,21 +132,30 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
125
132
  // whatever the formData object delivers
126
133
  // the partialIdsArray arr is almost deprecated legacy code where we allowed to send a separate list of partial
127
134
  // ids for reduced load and server processing, this will be removed soon, we can handle the same via execute
128
- // anyway TODO remove the partial ids array
129
- let formData: XhrFormData = new XhrFormData(this.sourceForm, viewState, executesArr(), this.partialIdsArray);
135
+ // anyway TODO reimplement the partial ids array, we still do not have it in jsf the way we need it
136
+ let formData: XhrFormData = new XhrFormData(this.sourceForm, resoveNamingContainerMapper(this.internalContext), executesArr(), this.partialIdsArray);
130
137
 
131
138
  this.contentType = formData.isMultipartRequest ? "undefined" : this.contentType;
132
139
 
133
140
  // next step the pass through parameters are merged in for post params
141
+ this.requestContext.$nspEnabled = false;
134
142
  let requestContext = this.requestContext;
135
- let passThroughParams = requestContext.getIf(CTX_PARAM_PASS_THR);
143
+ let requestPassThroughParams = requestContext.getIf(CTX_PARAM_REQ_PASS_THR) as ExtConfig;
136
144
 
145
+ // we are turning off here the jsf, faces remapping because we are now dealing with
146
+ // pass-through parameters
147
+ requestPassThroughParams.$nspEnabled = false;
137
148
  // this is an extension where we allow pass through parameters to be sent down additionally
138
149
  // this can be used and is used in the impl to enrich the post request parameters with additional
139
150
  // information
140
- formData.shallowMerge(passThroughParams, true, true);
151
+ try {
152
+ formData.shallowMerge(requestPassThroughParams, true, true);
153
+ } finally {
154
+ this.requestContext.$nspEnabled = true;
155
+ requestPassThroughParams.$nspEnabled = true;
156
+ }
141
157
 
142
- this.responseContext = passThroughParams.deepCopy;
158
+ this.responseContext = requestPassThroughParams.deepCopy;
143
159
 
144
160
  // we have to shift the internal passthroughs around to build up our response context
145
161
  let responseContext = this.responseContext;
@@ -170,9 +186,7 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
170
186
  ignoreErr(() => xhrObject.setRequestHeader(REQ_ACCEPT, STD_ACCEPT));
171
187
 
172
188
  this.sendEvent(BEGIN);
173
-
174
189
  this.sendRequest(formData);
175
-
176
190
  } catch (e) {
177
191
  // _onError
178
192
  this.handleError(e);
@@ -290,7 +304,7 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
290
304
  return;
291
305
  }
292
306
 
293
- (window?.faces ?? window.jsf).ajax.response(this.xhrObject, this.responseContext.value ?? {});
307
+ $faces().ajax.response(this.xhrObject, this.responseContext.value ?? {});
294
308
  }
295
309
 
296
310
  private handleMalFormedXML(resolve: Function) {
@@ -300,9 +314,9 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
300
314
  status: MALFORMEDXML,
301
315
  responseCode: 200,
302
316
  responseText: this.xhrObject?.responseText,
303
- source: {
304
- id: this.source.id.value
305
- }
317
+ // we remap the element just in case it gets replaced
318
+ // it will be unremapped
319
+ source: this.source.id.value
306
320
  };
307
321
  try {
308
322
  this.handleError(errorData, true);
@@ -352,6 +366,7 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
352
366
 
353
367
  Implementation.sendEvent(eventData, eventHandler);
354
368
  } catch (e) {
369
+ e.source = e?.source ?? this.requestContext.getIf(SOURCE).value;
355
370
  this.handleError(e);
356
371
  throw e;
357
372
  }
@@ -364,4 +379,5 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
364
379
  Implementation.sendError(errorData, eventHandler);
365
380
  }
366
381
 
382
+
367
383
  }
@@ -62,18 +62,23 @@ export module oam {
62
62
  DQ.byId(element).delete();
63
63
  };
64
64
 
65
- // noinspection JSUnusedGlobalSymbols
65
+ // noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
66
66
  /**
67
67
  * does special form submit remapping
68
68
  * re-maps the issuing command link into something,
69
- * a decode of the command link on the server can understand
69
+ * the "decode" of the command link on the server can understand
70
70
  *
71
71
  * @param formName
72
72
  * @param linkId
73
73
  * @param target
74
74
  * @param params
75
75
  */
76
- export const submitForm = function (formName: string, linkId: string, target: string, params: { [key: string]: any }): boolean {
76
+ export const submitForm = function (formName: string, linkId: string | null = null, target: string |null = null, params: AssocArr<any> | Tuples<string, any> | null = {} ): boolean {
77
+
78
+
79
+ //handle a possible incoming null, not sure if this is used that way anywhere, but we allow it
80
+ params = (!params) ? {} : params;
81
+
77
82
  let clearFn = 'clearFormHiddenParams_' + formName.replace(/-/g, '\$:').replace(/:/g, '_');
78
83
  window?.[clearFn]?.(formName);
79
84
 
@@ -81,18 +86,23 @@ export module oam {
81
86
  if (window?.myfaces?.core?.config?.autoScroll && (window as any)?.getScrolling) {
82
87
  myfaces.oam.setHiddenInput(formName, 'autoScroll', (window as any)?.getScrolling());
83
88
  }
84
- Stream.ofAssoc(params).each((param: [string, any]) => {
85
- myfaces.oam.setHiddenInput(formName, param[0], param[1]);
86
- });
89
+ let paramsStream: Stream<[string, any]> = Array.isArray(params) ? Stream.of(...params) : Stream.ofAssoc(params);
90
+ paramsStream.each(([key, data]) => myfaces.oam.setHiddenInput(formName, key, data));
87
91
 
88
92
  //we call the namespaced function, to allow decoration, via a direct call we would
89
- myfaces.oam.setHiddenInput(formName, `${formName}:_idcl`, linkId);
93
+ myfaces.oam.setHiddenInput(formName, `${formName}:_idcl`, linkId ?? '');
94
+
90
95
 
91
- DQ.byId(document.forms[formName]).each(form => {
96
+ DQ.byId(document.forms?.[formName] ?? document.getElementById(formName)).each(form => {
92
97
  const ATTR_TARGET = "target";
93
98
  const formElement = form.getAsElem(0).value as HTMLFormElement;
94
- const oldTarget = form.attr(ATTR_TARGET).value;
95
- form.attr(ATTR_TARGET).value = target;
99
+ const oldTarget = (form.getAsElem(0).value as HTMLFormElement).getAttribute("target");
100
+
101
+ if(target != "null" && target) {
102
+ (form.getAsElem(0).value as HTMLFormElement).setAttribute("target", target);
103
+ }
104
+
105
+
96
106
 
97
107
  const result = formElement?.onsubmit?.(null);
98
108
 
@@ -103,9 +113,15 @@ export module oam {
103
113
  } catch (e) {
104
114
  window?.console.error(e);
105
115
  } finally {
106
- form.attr(ATTR_TARGET).value = oldTarget;
107
- Stream.ofAssoc(params).each((param: [string, any]) => {
108
- myfaces.oam.clearHiddenInput(formName, param[0]);
116
+ if(oldTarget == null || oldTarget == "null") {
117
+ (form.getAsElem(0).value as HTMLFormElement).removeAttribute("target");
118
+ } else {
119
+ (form.getAsElem(0).value as HTMLFormElement).setAttribute("target", oldTarget);
120
+ }
121
+
122
+ // noinspection JSUnusedLocalSymbols
123
+ paramsStream.each(([key, data]) => {
124
+ myfaces.oam.clearHiddenInput(formName, key);
109
125
  });
110
126
  myfaces.oam.clearHiddenInput(formName, `${formName}:_idcl`);
111
127
  }
@@ -319,7 +319,7 @@ describe('DOMQuery tests', function () {
319
319
 
320
320
  it('it must have parents', function () {
321
321
  let probe1 = new DomQuery(document).querySelectorAll("div");
322
- let coll: Array<any> = probe1.parents("body").stream.collect(new ArrayCollector());
322
+ let coll: Array<any> = probe1.firstParent("body").stream.collect(new ArrayCollector());
323
323
  expect(coll.length == 1).to.be.true;
324
324
 
325
325
  });