Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
AbstractFormWidget |
|
| 1.2857142857142858;1.286 |
1 | // Copyright May 4, 2006 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | package org.apache.tapestry.dojo.form; |
|
15 | ||
16 | import org.apache.tapestry.IMarkupWriter; |
|
17 | import org.apache.tapestry.IRequestCycle; |
|
18 | import org.apache.tapestry.form.AbstractFormComponent; |
|
19 | ||
20 | ||
21 | /** |
|
22 | * Represents a dojo widget that manages an html form input |
|
23 | * field. |
|
24 | * |
|
25 | * @author jkuhnert |
|
26 | * @since 4.1 |
|
27 | */ |
|
28 | 8 | public abstract class AbstractFormWidget extends AbstractFormComponent implements IFormWidget |
29 | { |
|
30 | ||
31 | public abstract void setDestroy(boolean destroy); |
|
32 | ||
33 | /** |
|
34 | * Determined dynamically at runtime during rendering, informs widget implementations |
|
35 | * if they should destroy their client side widget equivalents or leave them in tact. |
|
36 | * |
|
37 | * @return True if the widget should be destroyed on this render, false otherwise. |
|
38 | */ |
|
39 | public abstract boolean getDestroy(); |
|
40 | ||
41 | /** |
|
42 | * {@inheritDoc} |
|
43 | */ |
|
44 | public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) |
|
45 | { |
|
46 | 0 | renderComponent(writer, cycle); |
47 | 0 | } |
48 | ||
49 | /** |
|
50 | * {@inheritDoc} |
|
51 | */ |
|
52 | protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
53 | { |
|
54 | 4 | if(!cycle.isRewinding()) { |
55 | ||
56 | 4 | if (!cycle.getResponseBuilder().isDynamic() |
57 | || cycle.getResponseBuilder().explicitlyContains(this)) { |
|
58 | ||
59 | 4 | setDestroy(false); |
60 | } else { |
|
61 | ||
62 | 0 | setDestroy(true); |
63 | } |
|
64 | } |
|
65 | ||
66 | 4 | renderFormWidget(writer, cycle); |
67 | 4 | } |
68 | ||
69 | /** |
|
70 | * {@inheritDoc} |
|
71 | */ |
|
72 | protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
73 | { |
|
74 | 1 | rewindFormWidget(writer, cycle); |
75 | 1 | } |
76 | ||
77 | /** |
|
78 | * Called when rendering a form widget. |
|
79 | * |
|
80 | * @param writer |
|
81 | * The markup writer to render with. |
|
82 | * @param cycle |
|
83 | * The cycle associated with request. |
|
84 | */ |
|
85 | protected abstract void renderFormWidget(IMarkupWriter writer, IRequestCycle cycle); |
|
86 | ||
87 | /** |
|
88 | * Called during form submission to retrieve submitted input values. |
|
89 | * Components should do any validation/retrieval of values in this method. |
|
90 | * |
|
91 | * @param writer |
|
92 | * The passed in {@link IMarkupWriter} will be a {@link org.apache.tapestry.engine.NullWriter}, making |
|
93 | * any content written ignored. |
|
94 | * @param cycle |
|
95 | * Typically used to retrieve submitted value via <code>cycle.getParameter(getName())</code>. |
|
96 | */ |
|
97 | protected abstract void rewindFormWidget(IMarkupWriter writer, IRequestCycle cycle); |
|
98 | } |