1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.taglib.html;
22
23 import org.apache.struts.taglib.TagUtils;
24 import org.apache.struts.util.MessageResources;
25
26 import javax.servlet.jsp.JspException;
27
28
29
30
31
32
33
34 public class RadioTag extends BaseHandlerTag {
35
36
37
38
39
40 protected static MessageResources messages =
41 MessageResources.getMessageResources(Constants.Package
42 + ".LocalStrings");
43
44
45
46
47 protected String name = Constants.BEAN_KEY;
48
49
50
51
52 protected String property = null;
53
54
55
56
57 protected String text = null;
58
59
60
61
62 protected String value = null;
63
64
65
66
67
68
69
70
71
72 protected String idName = null;
73
74 public String getName() {
75 return (this.name);
76 }
77
78 public void setName(String name) {
79 this.name = name;
80 }
81
82
83
84
85
86
87 public String getProperty() {
88 return (this.property);
89 }
90
91
92
93
94
95
96 public void setProperty(String property) {
97 this.property = property;
98 }
99
100
101
102
103 public String getValue() {
104 return (this.value);
105 }
106
107
108
109
110
111
112 public void setValue(String value) {
113 this.value = value;
114 }
115
116
117
118
119
120
121 public String getIdName() {
122 return (this.idName);
123 }
124
125
126
127
128
129
130
131 public void setIdName(String idName) {
132 this.idName = idName;
133 }
134
135
136
137
138
139
140
141
142 public int doStartTag() throws JspException {
143 String radioTag = renderRadioElement(serverValue(), currentValue());
144
145 TagUtils.getInstance().write(pageContext, radioTag);
146
147 this.text = null;
148
149 return (EVAL_BODY_TAG);
150 }
151
152
153
154
155
156
157
158 private String serverValue()
159 throws JspException {
160
161 if (this.idName == null) {
162 return this.value;
163 }
164
165 String serverValue = this.lookupProperty(this.idName, this.value);
166
167 return (serverValue == null) ? "" : serverValue;
168 }
169
170
171
172
173
174
175
176
177
178 private String currentValue()
179 throws JspException {
180 String current = this.lookupProperty(this.name, this.property);
181
182 return (current == null) ? "" : current;
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197 protected String renderRadioElement(String serverValue, String checkedValue)
198 throws JspException {
199 StringBuffer results = new StringBuffer("<input type=\"radio\"");
200
201 prepareAttribute(results, "name", prepareName());
202 prepareAttribute(results, "accesskey", getAccesskey());
203 prepareAttribute(results, "tabindex", getTabindex());
204 prepareAttribute(results, "value",
205 TagUtils.getInstance().filter(serverValue));
206
207 if (serverValue.equals(checkedValue)) {
208 results.append(" checked=\"checked\"");
209 }
210
211 results.append(prepareEventHandlers());
212 results.append(prepareStyles());
213 prepareOtherAttributes(results);
214 results.append(getElementClose());
215
216 return results.toString();
217 }
218
219
220
221
222
223
224 public int doAfterBody() throws JspException {
225 if (this.bodyContent != null) {
226 String value = this.bodyContent.getString().trim();
227
228 if (value.length() > 0) {
229 this.text = value;
230 }
231 }
232
233 return (SKIP_BODY);
234 }
235
236
237
238
239
240
241 public int doEndTag() throws JspException {
242
243 if (this.text != null) {
244 TagUtils.getInstance().write(pageContext, text);
245 }
246
247 return (EVAL_PAGE);
248 }
249
250
251
252
253
254
255 protected String prepareName()
256 throws JspException {
257 if (property == null) {
258 return null;
259 }
260
261
262 if (indexed) {
263 StringBuffer results = new StringBuffer();
264
265 prepareIndex(results, name);
266 results.append(property);
267
268 return results.toString();
269 }
270
271 return property;
272 }
273
274
275
276
277 public void release() {
278 super.release();
279 idName = null;
280 name = Constants.BEAN_KEY;
281 property = null;
282 text = null;
283 value = null;
284 }
285 }