|
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.Location; |
|
19 |
| import org.apache.tapestry.AbstractComponent; |
|
20 |
| import org.apache.tapestry.IActionListener; |
|
21 |
| import org.apache.tapestry.IComponent; |
|
22 |
| import org.apache.tapestry.IDirect; |
|
23 |
| import org.apache.tapestry.IForm; |
|
24 |
| import org.apache.tapestry.IMarkupWriter; |
|
25 |
| import org.apache.tapestry.IRender; |
|
26 |
| import org.apache.tapestry.IRequestCycle; |
|
27 |
| import org.apache.tapestry.RenderRewoundException; |
|
28 |
| import org.apache.tapestry.Tapestry; |
|
29 |
| import org.apache.tapestry.TapestryUtils; |
|
30 |
| import org.apache.tapestry.engine.ActionServiceParameter; |
|
31 |
| import org.apache.tapestry.engine.DirectServiceParameter; |
|
32 |
| import org.apache.tapestry.engine.IEngineService; |
|
33 |
| import org.apache.tapestry.engine.ILink; |
|
34 |
| import org.apache.tapestry.listener.ListenerInvoker; |
|
35 |
| import org.apache.tapestry.valid.IValidationDelegate; |
|
36 |
| import org.apache.tapestry.web.WebResponse; |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| public abstract class Form extends AbstractComponent implements IForm, IDirect |
|
64 |
| { |
|
65 |
| private String _name; |
|
66 |
| |
|
67 |
| private FormSupport _formSupport; |
|
68 |
| |
|
69 |
| private class RenderInformalParameters implements IRender |
|
70 |
| { |
|
71 |
129
| public void render(IMarkupWriter writer, IRequestCycle cycle)
|
|
72 |
| { |
|
73 |
129
| renderInformalParameters(writer, cycle);
|
|
74 |
| } |
|
75 |
| } |
|
76 |
| |
|
77 |
| private IRender _renderInformalParameters; |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
0
| public static IForm get(IRequestCycle cycle)
|
|
88 |
| { |
|
89 |
0
| return (IForm) cycle.getAttribute(ATTRIBUTE_NAME);
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
471
| public boolean isRewinding()
|
|
100 |
| { |
|
101 |
471
| if (!isRendering())
|
|
102 |
0
| throw Tapestry.createRenderOnlyPropertyException(this, "rewinding");
|
|
103 |
| |
|
104 |
471
| return _formSupport.isRewinding();
|
|
105 |
| } |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| public abstract IEngineService getDirectService(); |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| public abstract IEngineService getActionService(); |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| public abstract boolean isDirect(); |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
3
| public boolean getRequiresSession()
|
|
141 |
| { |
|
142 |
3
| return isStateful();
|
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
288
| public String getElementId(IFormComponent component)
|
|
157 |
| { |
|
158 |
288
| return _formSupport.getElementId(component, component.getId());
|
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
0
| public String getElementId(IFormComponent component, String baseId)
|
|
172 |
| { |
|
173 |
0
| return _formSupport.getElementId(component, baseId);
|
|
174 |
| } |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
141
| public String getName()
|
|
191 |
| { |
|
192 |
141
| return _name;
|
|
193 |
| } |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
228
| protected void prepareForRender(IRequestCycle cycle)
|
|
198 |
| { |
|
199 |
228
| super.prepareForRender(cycle);
|
|
200 |
| |
|
201 |
228
| TapestryUtils.storeForm(cycle, this);
|
|
202 |
| } |
|
203 |
| |
|
204 |
228
| protected void cleanupAfterRender(IRequestCycle cycle)
|
|
205 |
| { |
|
206 |
228
| _formSupport = null;
|
|
207 |
| |
|
208 |
228
| TapestryUtils.removeForm(cycle);
|
|
209 |
| |
|
210 |
228
| IValidationDelegate delegate = getDelegate();
|
|
211 |
| |
|
212 |
228
| if (delegate != null)
|
|
213 |
228
| delegate.setFormComponent(null);
|
|
214 |
| |
|
215 |
228
| super.cleanupAfterRender(cycle);
|
|
216 |
| } |
|
217 |
| |
|
218 |
228
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
219 |
| { |
|
220 |
228
| String actionId = cycle.getNextActionId();
|
|
221 |
| |
|
222 |
228
| _formSupport = newFormSupport(writer, cycle);
|
|
223 |
| |
|
224 |
228
| if (isRewinding())
|
|
225 |
| { |
|
226 |
81
| String submitType = _formSupport.rewind();
|
|
227 |
| |
|
228 |
75
| IActionListener listener = findListener(submitType);
|
|
229 |
| |
|
230 |
75
| getListenerInvoker().invokeListener(listener, this, cycle);
|
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
75
| throw new RenderRewoundException(this);
|
|
235 |
| } |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
| |
|
240 |
147
| String baseName = isDirect() ? constructFormNameForDirectService(cycle)
|
|
241 |
| : constructFormNameForActionService(actionId); |
|
242 |
| |
|
243 |
147
| _name = baseName + getResponse().getNamespace();
|
|
244 |
| |
|
245 |
147
| if (_renderInformalParameters == null)
|
|
246 |
81
| _renderInformalParameters = new RenderInformalParameters();
|
|
247 |
| |
|
248 |
147
| ILink link = getLink(cycle, actionId);
|
|
249 |
| |
|
250 |
147
| _formSupport.render(getMethod(), _renderInformalParameters, link, getScheme(), getPort());
|
|
251 |
| } |
|
252 |
| |
|
253 |
93
| IActionListener findListener(String mode)
|
|
254 |
| { |
|
255 |
93
| IActionListener result = null;
|
|
256 |
| |
|
257 |
93
| if (mode.equals(FormConstants.SUBMIT_CANCEL))
|
|
258 |
6
| result = getCancel();
|
|
259 |
87
| else if (mode.equals(FormConstants.SUBMIT_REFRESH))
|
|
260 |
6
| result = getRefresh();
|
|
261 |
81
| else if (!getDelegate().getHasErrors())
|
|
262 |
78
| result = getSuccess();
|
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
| |
|
268 |
93
| if (result == null)
|
|
269 |
84
| result = getListener();
|
|
270 |
| |
|
271 |
93
| return result;
|
|
272 |
| } |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
| |
|
281 |
24
| protected String constructFormNameForActionService(String actionId)
|
|
282 |
| { |
|
283 |
24
| return "Form" + actionId;
|
|
284 |
| } |
|
285 |
| |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
114
| private String constructFormNameForDirectService(IRequestCycle cycle)
|
|
295 |
| { |
|
296 |
114
| return cycle.getUniqueId(TapestryUtils.convertTapestryIdToNMToken(getId()));
|
|
297 |
| } |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
189
| protected FormSupport newFormSupport(IMarkupWriter writer, IRequestCycle cycle)
|
|
304 |
| { |
|
305 |
189
| return new FormSupportImpl(writer, cycle, this);
|
|
306 |
| } |
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
0
| public void addEventHandler(FormEventType type, String functionName)
|
|
315 |
| { |
|
316 |
0
| _formSupport.addEventHandler(type, functionName);
|
|
317 |
| } |
|
318 |
| |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
| |
|
325 |
63
| public void rewind(IMarkupWriter writer, IRequestCycle cycle)
|
|
326 |
| { |
|
327 |
63
| render(writer, cycle);
|
|
328 |
| } |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
63
| public void trigger(IRequestCycle cycle)
|
|
337 |
| { |
|
338 |
63
| cycle.rewindForm(this);
|
|
339 |
| } |
|
340 |
| |
|
341 |
| |
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
| |
|
347 |
147
| protected ILink getLink(IRequestCycle cycle, String actionId)
|
|
348 |
| { |
|
349 |
147
| if (isDirect())
|
|
350 |
| { |
|
351 |
114
| Object parameter = new DirectServiceParameter(this);
|
|
352 |
114
| return getDirectService().getLink(true, parameter);
|
|
353 |
| } |
|
354 |
| |
|
355 |
| |
|
356 |
| |
|
357 |
33
| Object parameter = new ActionServiceParameter(this, actionId);
|
|
358 |
| |
|
359 |
33
| return getActionService().getLink(true, parameter);
|
|
360 |
| } |
|
361 |
| |
|
362 |
| |
|
363 |
| |
|
364 |
| public abstract WebResponse getResponse(); |
|
365 |
| |
|
366 |
| |
|
367 |
| |
|
368 |
| |
|
369 |
| |
|
370 |
| public abstract IValidationDelegate getDelegate(); |
|
371 |
| |
|
372 |
| |
|
373 |
| public abstract IActionListener getListener(); |
|
374 |
| |
|
375 |
| |
|
376 |
| public abstract IActionListener getSuccess(); |
|
377 |
| |
|
378 |
| |
|
379 |
| public abstract IActionListener getCancel(); |
|
380 |
| |
|
381 |
| |
|
382 |
| public abstract IActionListener getRefresh(); |
|
383 |
| |
|
384 |
| |
|
385 |
| public abstract String getMethod(); |
|
386 |
| |
|
387 |
| |
|
388 |
| public abstract boolean isStateful(); |
|
389 |
| |
|
390 |
| |
|
391 |
| public abstract String getScheme(); |
|
392 |
| |
|
393 |
| |
|
394 |
| public abstract Integer getPort(); |
|
395 |
| |
|
396 |
6
| public void setEncodingType(String encodingType)
|
|
397 |
| { |
|
398 |
6
| _formSupport.setEncodingType(encodingType);
|
|
399 |
| } |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
90
| public void addHiddenValue(String name, String value)
|
|
404 |
| { |
|
405 |
90
| _formSupport.addHiddenValue(name, value);
|
|
406 |
| } |
|
407 |
| |
|
408 |
| |
|
409 |
| |
|
410 |
12
| public void addHiddenValue(String name, String id, String value)
|
|
411 |
| { |
|
412 |
12
| _formSupport.addHiddenValue(name, id, value);
|
|
413 |
| } |
|
414 |
| |
|
415 |
0
| public void prerenderField(IMarkupWriter writer, IComponent field, Location location)
|
|
416 |
| { |
|
417 |
0
| _formSupport.prerenderField(writer, field, location);
|
|
418 |
| } |
|
419 |
| |
|
420 |
225
| public boolean wasPrerendered(IMarkupWriter writer, IComponent field)
|
|
421 |
| { |
|
422 |
225
| return _formSupport.wasPrerendered(writer, field);
|
|
423 |
| } |
|
424 |
| |
|
425 |
| |
|
426 |
| |
|
427 |
0
| public void addDeferredRunnable(Runnable runnable)
|
|
428 |
| { |
|
429 |
0
| _formSupport.addDeferredRunnable(runnable);
|
|
430 |
| } |
|
431 |
| |
|
432 |
| |
|
433 |
| |
|
434 |
| |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
| public abstract ListenerInvoker getListenerInvoker(); |
|
439 |
| |
|
440 |
0
| public void registerForFocus(IFormComponent field, int priority)
|
|
441 |
| { |
|
442 |
0
| _formSupport.registerForFocus(field, priority);
|
|
443 |
| } |
|
444 |
| |
|
445 |
| } |