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