|
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.tapestry.AbstractComponent; |
|
18 |
| import org.apache.tapestry.IForm; |
|
19 |
| import org.apache.tapestry.IMarkupWriter; |
|
20 |
| import org.apache.tapestry.IRequestCycle; |
|
21 |
| import org.apache.tapestry.TapestryUtils; |
|
22 |
| import org.apache.tapestry.valid.IValidationDelegate; |
|
23 |
| import org.apache.tapestry.valid.ValidationConstants; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public abstract class AbstractFormComponent extends AbstractComponent implements IFormComponent |
|
34 |
| { |
|
35 |
| public abstract IForm getForm(); |
|
36 |
| |
|
37 |
| public abstract void setForm(IForm form); |
|
38 |
| |
|
39 |
| public abstract String getName(); |
|
40 |
| |
|
41 |
| public abstract void setName(String name); |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
120
| protected boolean getCanTakeFocus()
|
|
50 |
| { |
|
51 |
120
| return !isDisabled();
|
|
52 |
| } |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| public abstract String getIdParameter(); |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| public abstract void setClientId(String id); |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
123
| protected void renderIdAttribute(IMarkupWriter writer, IRequestCycle cycle)
|
|
74 |
| { |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
123
| String rawId = getIdParameter();
|
|
79 |
| |
|
80 |
123
| if (rawId == null)
|
|
81 |
75
| return;
|
|
82 |
| |
|
83 |
48
| String id = cycle.getUniqueId(TapestryUtils.convertTapestryIdToNMToken(rawId));
|
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
48
| setClientId(id);
|
|
88 |
| |
|
89 |
48
| writer.attribute("id", id);
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
366
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
97 |
| { |
|
98 |
366
| IForm form = TapestryUtils.getForm(cycle, this);
|
|
99 |
| |
|
100 |
363
| setForm(form);
|
|
101 |
| |
|
102 |
363
| if (form.wasPrerendered(writer, this))
|
|
103 |
15
| return;
|
|
104 |
| |
|
105 |
348
| IValidationDelegate delegate = form.getDelegate();
|
|
106 |
| |
|
107 |
348
| delegate.setFormComponent(this);
|
|
108 |
| |
|
109 |
348
| setName(form);
|
|
110 |
| |
|
111 |
345
| if (form.isRewinding())
|
|
112 |
| { |
|
113 |
147
| if (!isDisabled())
|
|
114 |
126
| rewindFormComponent(writer, cycle);
|
|
115 |
| |
|
116 |
| |
|
117 |
21
| else if (getAlwaysRenderBodyOnRewind())
|
|
118 |
3
| renderBody(writer, cycle);
|
|
119 |
| } |
|
120 |
198
| else if (!cycle.isRewinding())
|
|
121 |
| { |
|
122 |
177
| renderFormComponent(writer, cycle);
|
|
123 |
| |
|
124 |
171
| if (getCanTakeFocus() && !isDisabled())
|
|
125 |
| { |
|
126 |
93
| delegate.registerForFocus(
|
|
127 |
| this, |
|
128 |
93
| delegate.isInError() ? ValidationConstants.ERROR_FIELD
|
|
129 |
| : ValidationConstants.NORMAL_FIELD); |
|
130 |
| } |
|
131 |
| |
|
132 |
| } |
|
133 |
| } |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
18
| protected boolean getAlwaysRenderBodyOnRewind()
|
|
146 |
| { |
|
147 |
18
| return false;
|
|
148 |
| } |
|
149 |
| |
|
150 |
66
| protected void renderDelegatePrefix(IMarkupWriter writer, IRequestCycle cycle)
|
|
151 |
| { |
|
152 |
66
| getForm().getDelegate().writePrefix(writer, cycle, this, null);
|
|
153 |
| } |
|
154 |
| |
|
155 |
66
| protected void renderDelegateAttributes(IMarkupWriter writer, IRequestCycle cycle)
|
|
156 |
| { |
|
157 |
66
| getForm().getDelegate().writeAttributes(writer, cycle, this, null);
|
|
158 |
| } |
|
159 |
| |
|
160 |
63
| protected void renderDelegateSuffix(IMarkupWriter writer, IRequestCycle cycle)
|
|
161 |
| { |
|
162 |
63
| getForm().getDelegate().writeSuffix(writer, cycle, this, null);
|
|
163 |
| } |
|
164 |
| |
|
165 |
324
| protected void setName(IForm form)
|
|
166 |
| { |
|
167 |
324
| form.getElementId(this);
|
|
168 |
| } |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
0
| public boolean isRequired()
|
|
177 |
| { |
|
178 |
0
| return false;
|
|
179 |
| } |
|
180 |
| |
|
181 |
| protected abstract void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle); |
|
182 |
| |
|
183 |
| protected abstract void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle); |
|
184 |
| } |