1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.form; |
16 |
|
|
17 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
18 |
|
import org.apache.hivemind.HiveMind; |
19 |
|
import org.apache.hivemind.Location; |
20 |
|
import org.apache.hivemind.util.Defense; |
21 |
|
import org.apache.tapestry.*; |
22 |
|
import org.apache.tapestry.engine.ILink; |
23 |
|
import org.apache.tapestry.event.BrowserEvent; |
24 |
|
import org.apache.tapestry.javascript.JavascriptManager; |
25 |
|
import org.apache.tapestry.json.JSONObject; |
26 |
|
import org.apache.tapestry.services.DataSqueezer; |
27 |
|
import org.apache.tapestry.services.ResponseBuilder; |
28 |
|
import org.apache.tapestry.services.ServiceConstants; |
29 |
|
import org.apache.tapestry.valid.IValidationDelegate; |
30 |
|
|
31 |
|
import java.util.*; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
public class FormSupportImpl implements FormSupport |
38 |
|
{ |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
public static final String FORM_IDS = "formids"; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public static final String RESERVED_FORM_IDS = "reservedids"; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
public static final String SEED_IDS = "seedids"; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
public static final String SUBMIT_MODE = "submitmode"; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
public static final String FIELD_FOCUS_ATTRIBUTE = "org.apache.tapestry.field-focused"; |
75 |
|
|
76 |
|
private static final Set _standardReservedIds; |
77 |
|
|
78 |
|
static |
79 |
|
{ |
80 |
1 |
Set set = new HashSet(); |
81 |
|
|
82 |
1 |
set.addAll(Arrays.asList(ServiceConstants.RESERVED_IDS)); |
83 |
1 |
set.add(FORM_IDS); |
84 |
1 |
set.add(RESERVED_FORM_IDS); |
85 |
1 |
set.add(SEED_IDS); |
86 |
1 |
set.add(SUBMIT_MODE); |
87 |
1 |
set.add(FormConstants.SUBMIT_NAME_PARAMETER); |
88 |
|
|
89 |
1 |
_standardReservedIds = Collections.unmodifiableSet(set); |
90 |
|
} |
91 |
|
|
92 |
|
private static final Set _submitModes; |
93 |
|
|
94 |
|
static |
95 |
|
{ |
96 |
1 |
Set set = new HashSet(); |
97 |
1 |
set.add(FormConstants.SUBMIT_CANCEL); |
98 |
1 |
set.add(FormConstants.SUBMIT_NORMAL); |
99 |
1 |
set.add(FormConstants.SUBMIT_REFRESH); |
100 |
|
|
101 |
1 |
_submitModes = Collections.unmodifiableSet(set); |
102 |
1 |
} |
103 |
|
|
104 |
|
protected final IRequestCycle _cycle; |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
private int _allocatedIdIndex; |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
21 |
private final List _allocatedIds = new ArrayList(); |
119 |
|
|
120 |
|
private String _encodingType; |
121 |
|
|
122 |
21 |
private final List _deferredRunnables = new ArrayList(); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
21 |
private final Map _prerenderMap = new HashMap(); |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
private Map _events; |
137 |
|
|
138 |
|
private final IForm _form; |
139 |
|
|
140 |
21 |
private final List _hiddenValues = new ArrayList(); |
141 |
|
|
142 |
|
private final boolean _rewinding; |
143 |
|
|
144 |
|
private final IMarkupWriter _writer; |
145 |
|
|
146 |
|
private final IValidationDelegate _delegate; |
147 |
|
|
148 |
|
private final PageRenderSupport _pageRenderSupport; |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
private final JSONObject _profile; |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
private boolean _fieldUpdating; |
159 |
|
|
160 |
|
private JavascriptManager _javascriptManager; |
161 |
|
|
162 |
|
private String _idSeed; |
163 |
|
|
164 |
|
public FormSupportImpl(IMarkupWriter writer, IRequestCycle cycle, IForm form) |
165 |
|
{ |
166 |
20 |
this(writer, cycle, form, null); |
167 |
20 |
} |
168 |
|
|
169 |
|
public FormSupportImpl(IMarkupWriter writer, IRequestCycle cycle, |
170 |
|
IForm form, JavascriptManager javascriptManager) |
171 |
20 |
{ |
172 |
20 |
Defense.notNull(writer, "writer"); |
173 |
20 |
Defense.notNull(cycle, "cycle"); |
174 |
20 |
Defense.notNull(form, "form"); |
175 |
|
|
176 |
20 |
_writer = writer; |
177 |
20 |
_cycle = cycle; |
178 |
20 |
_form = form; |
179 |
20 |
_delegate = form.getDelegate(); |
180 |
|
|
181 |
20 |
_rewinding = cycle.isRewound(form); |
182 |
20 |
_allocatedIdIndex = 0; |
183 |
|
|
184 |
20 |
_pageRenderSupport = TapestryUtils.getOptionalPageRenderSupport(cycle); |
185 |
20 |
_profile = new JSONObject(); |
186 |
20 |
_javascriptManager = javascriptManager; |
187 |
20 |
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
FormSupportImpl(IRequestCycle cycle) |
196 |
1 |
{ |
197 |
1 |
_cycle = cycle; |
198 |
1 |
_form = null; |
199 |
1 |
_rewinding = false; |
200 |
1 |
_writer = null; |
201 |
1 |
_delegate = null; |
202 |
1 |
_pageRenderSupport = null; |
203 |
1 |
_profile = null; |
204 |
1 |
} |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
public IForm getForm() |
210 |
|
{ |
211 |
2 |
return _form; |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
public void addEventHandler(FormEventType type, String functionName) |
218 |
|
{ |
219 |
6 |
if (_events == null) |
220 |
3 |
_events = new HashMap(); |
221 |
|
|
222 |
6 |
List functionList = (List) _events.get(type); |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
6 |
if (functionList == null) |
229 |
|
{ |
230 |
3 |
functionList = new ArrayList(); |
231 |
|
|
232 |
3 |
_events.put(type, functionList); |
233 |
|
} |
234 |
|
|
235 |
6 |
functionList.add(functionName); |
236 |
6 |
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
private void addHiddenFieldsForLinkParameters(ILink link) |
248 |
|
{ |
249 |
11 |
String[] names = link.getParameterNames(); |
250 |
11 |
int count = Tapestry.size(names); |
251 |
|
|
252 |
11 |
StringBuffer extraIds = new StringBuffer(); |
253 |
11 |
String sep = ""; |
254 |
11 |
boolean hasExtra = false; |
255 |
|
|
256 |
22 |
for (int i = 0; i < count; i++) |
257 |
|
{ |
258 |
11 |
String name = names[i]; |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
11 |
if (!_standardReservedIds.contains(name)) |
263 |
|
{ |
264 |
1 |
_cycle.getUniqueId(name); |
265 |
|
|
266 |
1 |
extraIds.append(sep); |
267 |
1 |
extraIds.append(name); |
268 |
|
|
269 |
1 |
sep = ","; |
270 |
1 |
hasExtra = true; |
271 |
|
} |
272 |
|
|
273 |
11 |
addHiddenFieldsForLinkParameter(link, name); |
274 |
|
} |
275 |
|
|
276 |
11 |
if (hasExtra) |
277 |
1 |
addHiddenValue(RESERVED_FORM_IDS, extraIds.toString()); |
278 |
11 |
} |
279 |
|
|
280 |
|
public void addHiddenValue(String name, String value) |
281 |
|
{ |
282 |
35 |
_hiddenValues.add(new HiddenFieldData(name, value)); |
283 |
35 |
} |
284 |
|
|
285 |
|
public void addHiddenValue(String name, String id, String value) |
286 |
|
{ |
287 |
1 |
_hiddenValues.add(new HiddenFieldData(name, id, value)); |
288 |
1 |
} |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
private String buildAllocatedIdList() |
297 |
|
{ |
298 |
10 |
StringBuffer buffer = new StringBuffer(); |
299 |
10 |
int count = _allocatedIds.size(); |
300 |
|
|
301 |
16 |
for (int i = 0; i < count; i++) |
302 |
|
{ |
303 |
6 |
if (i > 0) |
304 |
2 |
buffer.append(','); |
305 |
|
|
306 |
6 |
buffer.append(_allocatedIds.get(i)); |
307 |
|
} |
308 |
|
|
309 |
10 |
return buffer.toString(); |
310 |
|
} |
311 |
|
|
312 |
|
private void emitEventHandlers(String formId) |
313 |
|
{ |
314 |
10 |
if (_events == null || _events.isEmpty()) |
315 |
7 |
return; |
316 |
|
|
317 |
3 |
StringBuffer buffer = new StringBuffer(); |
318 |
|
|
319 |
3 |
Iterator i = _events.entrySet().iterator(); |
320 |
|
|
321 |
6 |
while (i.hasNext()) |
322 |
|
{ |
323 |
3 |
Map.Entry entry = (Map.Entry) i.next(); |
324 |
3 |
FormEventType type = (FormEventType) entry.getKey(); |
325 |
3 |
Object value = entry.getValue(); |
326 |
|
|
327 |
3 |
buffer.append("Tapestry."); |
328 |
3 |
buffer.append(type.getAddHandlerFunctionName()); |
329 |
3 |
buffer.append("('"); |
330 |
3 |
buffer.append(formId); |
331 |
3 |
buffer.append("', function (event)\n{"); |
332 |
|
|
333 |
3 |
List l = (List) value; |
334 |
3 |
int count = l.size(); |
335 |
|
|
336 |
9 |
for (int j = 0; j < count; j++) |
337 |
|
{ |
338 |
6 |
String functionName = (String) l.get(j); |
339 |
|
|
340 |
6 |
if (j > 0) |
341 |
|
{ |
342 |
3 |
buffer.append(";"); |
343 |
|
} |
344 |
|
|
345 |
6 |
buffer.append("\n "); |
346 |
6 |
buffer.append(functionName); |
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
6 |
if (!functionName.endsWith(")")) |
352 |
|
{ |
353 |
5 |
buffer.append("()"); |
354 |
|
} |
355 |
|
} |
356 |
|
|
357 |
3 |
buffer.append(";\n});\n"); |
358 |
3 |
} |
359 |
|
|
360 |
|
|
361 |
|
|
362 |
3 |
_pageRenderSupport.addInitializationScript(_form, buffer.toString()); |
363 |
3 |
} |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
public String getElementId(IFormComponent component) |
375 |
|
{ |
376 |
20 |
return getElementId(component, component.getSpecifiedId()); |
377 |
|
} |
378 |
|
|
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
public String getElementId(IFormComponent component, String baseId) |
389 |
|
{ |
390 |
|
|
391 |
|
|
392 |
20 |
String filteredId = TapestryUtils.convertTapestryIdToNMToken(baseId); |
393 |
|
|
394 |
20 |
String result = _cycle.getUniqueId(filteredId); |
395 |
|
|
396 |
20 |
if (_rewinding) |
397 |
|
{ |
398 |
14 |
if (_allocatedIdIndex >= _allocatedIds.size()) |
399 |
|
{ |
400 |
1 |
throw new StaleLinkException(FormMessages.formTooManyIds(_form, _allocatedIds.size(), component), component); |
401 |
|
} |
402 |
|
|
403 |
13 |
String expected = (String) _allocatedIds.get(_allocatedIdIndex); |
404 |
|
|
405 |
13 |
if (!result.equals(expected)) |
406 |
1 |
throw new StaleLinkException(FormMessages.formIdMismatch( |
407 |
|
_form, |
408 |
|
_allocatedIdIndex, |
409 |
|
expected, |
410 |
|
result, |
411 |
|
component), component); |
412 |
12 |
} |
413 |
|
else |
414 |
|
{ |
415 |
6 |
_allocatedIds.add(result); |
416 |
|
} |
417 |
|
|
418 |
18 |
_allocatedIdIndex++; |
419 |
|
|
420 |
18 |
component.setName(result); |
421 |
18 |
component.setClientId(result); |
422 |
|
|
423 |
18 |
return result; |
424 |
|
} |
425 |
|
|
426 |
|
public String peekClientId(IFormComponent comp) |
427 |
|
{ |
428 |
0 |
String id = comp.getSpecifiedId(); |
429 |
|
|
430 |
0 |
if (id == null) |
431 |
0 |
return null; |
432 |
|
|
433 |
0 |
if (wasPrerendered(comp)) |
434 |
0 |
return comp.getClientId(); |
435 |
|
|
436 |
0 |
return _cycle.peekUniqueId(id); |
437 |
|
} |
438 |
|
|
439 |
|
public boolean isRewinding() |
440 |
|
{ |
441 |
0 |
return _rewinding; |
442 |
|
} |
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
|
private void reinitializeIdAllocatorForRewind() |
455 |
|
{ |
456 |
8 |
_cycle.initializeIdState(_cycle.getParameter(SEED_IDS)); |
457 |
|
|
458 |
8 |
String allocatedFormIds = _cycle.getParameter(FORM_IDS); |
459 |
|
|
460 |
8 |
String[] ids = TapestryUtils.split(allocatedFormIds); |
461 |
|
|
462 |
23 |
for (int i = 0; i < ids.length; i++) |
463 |
15 |
_allocatedIds.add(ids[i]); |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
8 |
String extraReservedIds = _cycle.getParameter(RESERVED_FORM_IDS); |
469 |
|
|
470 |
8 |
ids = TapestryUtils.split(extraReservedIds); |
471 |
|
|
472 |
9 |
for (int i = 0; i < ids.length; i++) |
473 |
|
{ |
474 |
1 |
_cycle.getUniqueId(ids[i]); |
475 |
|
} |
476 |
8 |
} |
477 |
|
|
478 |
|
public void render(String method, IRender informalParametersRenderer, ILink link, String scheme, Integer port) |
479 |
|
{ |
480 |
11 |
String formId = _form.getName(); |
481 |
|
|
482 |
11 |
_idSeed = _cycle.encodeIdState(); |
483 |
|
|
484 |
11 |
emitEventManagerInitialization(formId); |
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
|
489 |
11 |
addHiddenFieldsForLinkParameters(link); |
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
|
494 |
11 |
addHiddenValue(SUBMIT_MODE, null); |
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
11 |
addHiddenValue(FormConstants.SUBMIT_NAME_PARAMETER, null); |
500 |
|
|
501 |
11 |
IMarkupWriter nested = _writer.getNestedWriter(); |
502 |
|
|
503 |
11 |
_form.renderBody(nested, _cycle); |
504 |
|
|
505 |
10 |
runDeferredRunnables(); |
506 |
|
|
507 |
10 |
int portI = (port == null) ? 0 : port.intValue(); |
508 |
|
|
509 |
10 |
writeTag(_writer, method, link.getURL(scheme, null, portI, null, false)); |
510 |
|
|
511 |
|
|
512 |
|
|
513 |
10 |
_writer.attribute("id", formId); |
514 |
|
|
515 |
10 |
if (_encodingType != null) |
516 |
1 |
_writer.attribute("enctype", _encodingType); |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
10 |
emitEventHandlers(formId); |
521 |
|
|
522 |
10 |
informalParametersRenderer.render(_writer, _cycle); |
523 |
|
|
524 |
|
|
525 |
|
|
526 |
10 |
_writer.println(); |
527 |
|
|
528 |
10 |
writeHiddenFields(); |
529 |
|
|
530 |
|
|
531 |
|
|
532 |
10 |
nested.close(); |
533 |
|
|
534 |
|
|
535 |
|
|
536 |
10 |
_writer.end(); |
537 |
|
|
538 |
10 |
String fieldId = _delegate.getFocusField(); |
539 |
|
|
540 |
10 |
if (_pageRenderSupport == null) |
541 |
0 |
return; |
542 |
|
|
543 |
10 |
_pageRenderSupport.addInitializationScript(_form, "dojo.require(\"tapestry.form\");"); |
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
|
548 |
10 |
if (!_cycle.isFocusDisabled() && fieldId != null && _form.getFocus() |
549 |
|
&& _cycle.getAttribute(FIELD_FOCUS_ATTRIBUTE) == null) |
550 |
|
{ |
551 |
|
|
552 |
|
|
553 |
2 |
_pageRenderSupport.addScriptAfterInitialization(_form, "tapestry.form.focusField('" + fieldId + "');"); |
554 |
|
|
555 |
2 |
_cycle.setAttribute(FIELD_FOCUS_ATTRIBUTE, Boolean.TRUE); |
556 |
|
} |
557 |
|
|
558 |
|
|
559 |
|
|
560 |
10 |
if (_form.isClientValidationEnabled()) |
561 |
|
{ |
562 |
0 |
IPage page = _form.getPage(); |
563 |
|
|
564 |
|
|
565 |
|
|
566 |
0 |
if (!page.hasWidgets()) |
567 |
|
{ |
568 |
0 |
if (_javascriptManager != null && _javascriptManager.getFirstWidgetAsset() != null) |
569 |
|
{ |
570 |
0 |
_pageRenderSupport.addExternalScript(_form, |
571 |
|
_javascriptManager.getFirstWidgetAsset().getResourceLocation()); |
572 |
|
} |
573 |
|
} |
574 |
|
|
575 |
0 |
_pageRenderSupport.addInitializationScript(_form, "tapestry.form.clearProfiles('" |
576 |
|
+ formId + "'); tapestry.form.registerProfile('" + formId + "'," |
577 |
|
+ _profile.toString() + ");"); |
578 |
|
} |
579 |
10 |
} |
580 |
|
|
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
protected void emitEventManagerInitialization(String formId) |
589 |
|
{ |
590 |
11 |
if (_pageRenderSupport == null) |
591 |
0 |
return; |
592 |
|
|
593 |
11 |
StringBuffer str = new StringBuffer("dojo.require(\"tapestry.form\");"); |
594 |
11 |
str.append("tapestry.form.registerForm(\"").append(formId).append("\""); |
595 |
|
|
596 |
11 |
if (_form.isAsync()) |
597 |
|
{ |
598 |
0 |
str.append(", true"); |
599 |
|
|
600 |
0 |
if (_form.isJson()) |
601 |
|
{ |
602 |
0 |
str.append(", true"); |
603 |
|
} |
604 |
|
} |
605 |
|
|
606 |
11 |
str.append(");"); |
607 |
|
|
608 |
11 |
_pageRenderSupport.addInitializationScript(_form, str.toString()); |
609 |
11 |
} |
610 |
|
|
611 |
|
public String rewind() |
612 |
|
{ |
613 |
9 |
_form.getDelegate().clear(); |
614 |
|
|
615 |
9 |
String mode = _cycle.getParameter(SUBMIT_MODE); |
616 |
|
|
617 |
|
|
618 |
|
|
619 |
9 |
if (FormConstants.SUBMIT_CANCEL.equals(mode)) |
620 |
1 |
return mode; |
621 |
|
|
622 |
8 |
reinitializeIdAllocatorForRewind(); |
623 |
|
|
624 |
8 |
_form.renderBody(_writer, _cycle); |
625 |
|
|
626 |
|
|
627 |
|
|
628 |
|
|
629 |
6 |
BrowserEvent event = new BrowserEvent(_cycle); |
630 |
|
|
631 |
6 |
_form.getEventInvoker().invokeFormListeners(this, _cycle, event); |
632 |
|
|
633 |
6 |
int expected = _allocatedIds.size(); |
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
6 |
if (_allocatedIdIndex < expected) |
640 |
|
{ |
641 |
1 |
String nextExpectedId = (String) _allocatedIds.get(_allocatedIdIndex); |
642 |
|
|
643 |
1 |
throw new StaleLinkException(FormMessages.formTooFewIds(_form, expected - _allocatedIdIndex, nextExpectedId), _form); |
644 |
|
} |
645 |
|
|
646 |
5 |
runDeferredRunnables(); |
647 |
|
|
648 |
5 |
if (_submitModes.contains(mode)) |
649 |
|
{ |
650 |
|
|
651 |
|
|
652 |
5 |
if (FormConstants.SUBMIT_REFRESH.equals(mode)) |
653 |
|
{ |
654 |
1 |
_form.getDelegate().clearErrors(); |
655 |
|
} |
656 |
|
|
657 |
5 |
return mode; |
658 |
|
} |
659 |
|
|
660 |
|
|
661 |
|
|
662 |
|
|
663 |
0 |
return FormConstants.SUBMIT_NORMAL; |
664 |
|
} |
665 |
|
|
666 |
|
private void runDeferredRunnables() |
667 |
|
{ |
668 |
15 |
Iterator i = _deferredRunnables.iterator(); |
669 |
17 |
while (i.hasNext()) |
670 |
|
{ |
671 |
2 |
Runnable r = (Runnable) i.next(); |
672 |
|
|
673 |
2 |
r.run(); |
674 |
2 |
} |
675 |
15 |
} |
676 |
|
|
677 |
|
public void setEncodingType(String encodingType) |
678 |
|
{ |
679 |
|
|
680 |
3 |
if (_encodingType != null && !_encodingType.equals(encodingType)) |
681 |
1 |
throw new ApplicationRuntimeException(FormMessages.encodingTypeContention(_form, _encodingType, encodingType), |
682 |
|
_form, null, null); |
683 |
|
|
684 |
2 |
_encodingType = encodingType; |
685 |
2 |
} |
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
protected void writeHiddenField(IMarkupWriter writer, String name, String id, String value) |
691 |
|
{ |
692 |
53 |
writer.beginEmpty("input"); |
693 |
53 |
writer.attribute("type", "hidden"); |
694 |
53 |
writer.attribute("name", name); |
695 |
|
|
696 |
53 |
if (HiveMind.isNonBlank(id)) |
697 |
1 |
writer.attribute("id", id); |
698 |
|
|
699 |
53 |
writer.attribute("value", value == null ? "" : value); |
700 |
53 |
writer.println(); |
701 |
53 |
} |
702 |
|
|
703 |
|
|
704 |
|
|
705 |
|
|
706 |
|
|
707 |
|
|
708 |
|
|
709 |
|
|
710 |
|
protected void writeHiddenFields() |
711 |
|
{ |
712 |
10 |
IMarkupWriter writer = getHiddenFieldWriter(); |
713 |
|
|
714 |
10 |
writer.begin("div"); |
715 |
10 |
writer.attribute("style", "display:none;"); |
716 |
10 |
writer.attribute("id", _form.getName() + "hidden"); |
717 |
|
|
718 |
10 |
writeHiddenFieldList(writer); |
719 |
|
|
720 |
10 |
writer.end(); |
721 |
10 |
} |
722 |
|
|
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
protected void writeHiddenFieldList(IMarkupWriter writer) |
729 |
|
{ |
730 |
10 |
writeHiddenField(writer, FORM_IDS, null, buildAllocatedIdList()); |
731 |
10 |
writeHiddenField(writer, SEED_IDS, null, _idSeed); |
732 |
|
|
733 |
10 |
Iterator i = _hiddenValues.iterator(); |
734 |
43 |
while (i.hasNext()) |
735 |
|
{ |
736 |
33 |
HiddenFieldData data = (HiddenFieldData) i.next(); |
737 |
|
|
738 |
33 |
writeHiddenField(writer, data.getName(), data.getId(), data.getValue()); |
739 |
33 |
} |
740 |
10 |
} |
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
|
|
747 |
|
|
748 |
|
|
749 |
|
|
750 |
|
protected IMarkupWriter getHiddenFieldWriter() |
751 |
|
{ |
752 |
10 |
if (_cycle.getResponseBuilder().contains(_form) |
753 |
|
|| (!_fieldUpdating || !_cycle.getResponseBuilder().isDynamic()) ) |
754 |
|
{ |
755 |
10 |
return _writer; |
756 |
|
} |
757 |
|
|
758 |
0 |
return _cycle.getResponseBuilder().getWriter(_form.getName() + "hidden", ResponseBuilder.ELEMENT_TYPE); |
759 |
|
} |
760 |
|
|
761 |
|
private void addHiddenFieldsForLinkParameter(ILink link, String parameterName) |
762 |
|
{ |
763 |
11 |
String[] values = link.getParameterValues(parameterName); |
764 |
|
|
765 |
|
|
766 |
|
|
767 |
11 |
if (values == null) |
768 |
0 |
return; |
769 |
|
|
770 |
22 |
for (int i = 0; i < values.length; i++) |
771 |
|
{ |
772 |
11 |
addHiddenValue(parameterName, values[i]); |
773 |
|
} |
774 |
11 |
} |
775 |
|
|
776 |
|
protected void writeTag(IMarkupWriter writer, String method, String url) |
777 |
|
{ |
778 |
10 |
writer.begin("form"); |
779 |
10 |
writer.attribute("method", method); |
780 |
10 |
writer.attribute("action", url); |
781 |
10 |
} |
782 |
|
|
783 |
|
public void prerenderField(IMarkupWriter writer, IComponent field, Location location) |
784 |
|
{ |
785 |
2 |
Defense.notNull(writer, "writer"); |
786 |
2 |
Defense.notNull(field, "field"); |
787 |
|
|
788 |
2 |
String key = field.getExtendedId(); |
789 |
|
|
790 |
2 |
if (_prerenderMap.containsKey(key)) |
791 |
1 |
throw new ApplicationRuntimeException(FormMessages.fieldAlreadyPrerendered(field), field, location, null); |
792 |
|
|
793 |
1 |
NestedMarkupWriter nested = writer.getNestedWriter(); |
794 |
|
|
795 |
1 |
TapestryUtils.storePrerender(_cycle, field); |
796 |
|
|
797 |
1 |
_cycle.getResponseBuilder().render(nested, field, _cycle); |
798 |
|
|
799 |
1 |
TapestryUtils.removePrerender(_cycle); |
800 |
|
|
801 |
1 |
_prerenderMap.put(key, nested.getBuffer()); |
802 |
1 |
} |
803 |
|
|
804 |
|
public boolean wasPrerendered(IMarkupWriter writer, IComponent field) |
805 |
|
{ |
806 |
0 |
String key = field.getExtendedId(); |
807 |
|
|
808 |
|
|
809 |
|
|
810 |
|
|
811 |
0 |
if (!_prerenderMap.containsKey(key)) |
812 |
0 |
return false; |
813 |
|
|
814 |
0 |
String buffer = (String) _prerenderMap.get(key); |
815 |
|
|
816 |
0 |
writer.printRaw(buffer); |
817 |
|
|
818 |
0 |
_prerenderMap.remove(key); |
819 |
|
|
820 |
0 |
return true; |
821 |
|
} |
822 |
|
|
823 |
|
public boolean wasPrerendered(IComponent field) |
824 |
|
{ |
825 |
0 |
return _prerenderMap.containsKey(field.getExtendedId()); |
826 |
|
} |
827 |
|
|
828 |
|
public void addDeferredRunnable(Runnable runnable) |
829 |
|
{ |
830 |
2 |
Defense.notNull(runnable, "runnable"); |
831 |
|
|
832 |
2 |
_deferredRunnables.add(runnable); |
833 |
2 |
} |
834 |
|
|
835 |
|
public void registerForFocus(IFormComponent field, int priority) |
836 |
|
{ |
837 |
0 |
_delegate.registerForFocus(field, priority); |
838 |
0 |
} |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
|
public JSONObject getProfile() |
844 |
|
{ |
845 |
0 |
return _profile; |
846 |
|
} |
847 |
|
|
848 |
|
|
849 |
|
|
850 |
|
|
851 |
|
public boolean isFormFieldUpdating() |
852 |
|
{ |
853 |
0 |
return _fieldUpdating; |
854 |
|
} |
855 |
|
|
856 |
|
|
857 |
|
|
858 |
|
|
859 |
|
public void setFormFieldUpdating(boolean value) |
860 |
|
{ |
861 |
0 |
_fieldUpdating = value; |
862 |
0 |
} |
863 |
|
} |