KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > tags > form > AbstractHtmlElementTag


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.tags.form;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20
21 import org.springframework.util.ObjectUtils;
22 import org.springframework.util.StringUtils;
23
24 /**
25  * Base class for databinding-aware JSP tags that render HTML element. Provides
26  * a set of properties corresponding to the set of HTML attributes that are common
27  * across elements.
28  *
29  * @author Rob Harrop
30  * @since 2.0
31  */

32 public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElementTag {
33
34     /**
35      * The name of the '<code>class</code>' attribute.
36      */

37     public static final String JavaDoc CLASS_ATTRIBUTE = "class";
38
39     /**
40      * The name of the '<code>style</code>' attribute.
41      */

42     public static final String JavaDoc STYLE_ATTRIBUTE = "style";
43
44     /**
45      * The name of the '<code>lang</code>' attribute.
46      */

47     public static final String JavaDoc LANG_ATTRIBUTE = "lang";
48
49     /**
50      * The name of the '<code>title</code>' attribute.
51      */

52     public static final String JavaDoc TITLE_ATTRIBUTE = "title";
53
54     /**
55      * The name of the '<code>dir</code>' attribute.
56      */

57     public static final String JavaDoc DIR_ATTRIBUTE = "dir";
58
59     /**
60      * The name of the '<code>tabindex</code>' attribute.
61      */

62     public static final String JavaDoc TABINDEX_ATTRIBUTE = "tabindex";
63
64     /**
65      * The name of the '<code>onclick</code>' attribute.
66      */

67     public static final String JavaDoc ONCLICK_ATTRIBUTE = "onclick";
68
69     /**
70      * The name of the '<code>ondblclick</code>' attribute.
71      */

72     public static final String JavaDoc ONDBLCLICK_ATTRIBUTE = "ondblclick";
73
74     /**
75      * The name of the '<code>onmousedown</code>' attribute.
76      */

77     public static final String JavaDoc ONMOUSEDOWN_ATTRIBUTE = "onmousedown";
78
79     /**
80      * The name of the '<code>onmouseup</code>' attribute.
81      */

82     public static final String JavaDoc ONMOUSEUP_ATTRIBUTE = "onmouseup";
83
84     /**
85      * The name of the '<code>onmouseover</code>' attribute.
86      */

87     public static final String JavaDoc ONMOUSEOVER_ATTRIBUTE = "onmouseover";
88
89     /**
90      * The name of the '<code>onmousemove</code>' attribute.
91      */

92     public static final String JavaDoc ONMOUSEMOVE_ATTRIBUTE = "onmousemove";
93
94     /**
95      * The name of the '<code>onmouseout</code>' attribute.
96      */

97     public static final String JavaDoc ONMOUSEOUT_ATTRIBUTE = "onmouseout";
98
99     /**
100      * The name of the '<code>onkeypress</code>' attribute.
101      */

102     public static final String JavaDoc ONKEYPRESS_ATTRIBUTE = "onkeypress";
103
104     /**
105      * The name of the '<code>onkeyup</code>' attribute.
106      */

107     public static final String JavaDoc ONKEYUP_ATTRIBUTE = "onkeyup";
108
109     /**
110      * The name of the '<code>onkeydown</code>' attribute.
111      */

112     public static final String JavaDoc ONKEYDOWN_ATTRIBUTE = "onkeydown";
113
114
115     /**
116      * The value of the '<code>class</code>' attribute.
117      */

118     private String JavaDoc cssClass;
119
120     /**
121      * The CSS class to use when the field bound to a particular tag has errors.
122      */

123     private String JavaDoc cssErrorClass;
124
125     /**
126      * The value of the '<code>style</code>' attribute.
127      */

128     private String JavaDoc cssStyle;
129
130     /**
131      * The value of the '<code>lang</code>' attribute.
132      */

133     private String JavaDoc lang;
134
135     /**
136      * The value of the '<code>title</code>' attribute.
137      */

138     private String JavaDoc title;
139
140     /**
141      * The value of the '<code>dir</code>' attribute.
142      */

143     private String JavaDoc dir;
144
145     /**
146      * The value of the '<code>tabindex</code>' attribute.
147      */

148     private String JavaDoc tabindex;
149
150     /**
151      * The value of the '<code>onclick</code>' attribute.
152      */

153     private String JavaDoc onclick;
154
155     /**
156      * The value of the '<code>ondblclick</code>' attribute.
157      */

158     private String JavaDoc ondblclick;
159
160     /**
161      * The value of the '<code>onmousedown</code>' attribute.
162      */

163     private String JavaDoc onmousedown;
164
165     /**
166      * The value of the '<code>onmouseup</code>' attribute.
167      */

168     private String JavaDoc onmouseup;
169
170     /**
171      * The value of the '<code>onmouseover</code>' attribute.
172      */

173     private String JavaDoc onmouseover;
174
175     /**
176      * The value of the '<code>onmousemove</code>' attribute.
177      */

178     private String JavaDoc onmousemove;
179
180     /**
181      * The value of the '<code>onmouseout</code>' attribute.
182      */

183     private String JavaDoc onmouseout;
184
185     /**
186      * The value of the '<code>onkeypress</code>' attribute.
187      */

188     private String JavaDoc onkeypress;
189
190     /**
191      * The value of the '<code>onkeyup</code>' attribute.
192      */

193     private String JavaDoc onkeyup;
194
195     /**
196      * The value of the '<code>onkeydown</code>' attribute.
197      */

198     private String JavaDoc onkeydown;
199
200
201     /**
202      * Sets the value of the '<code>class</code>' attribute.
203      * May be a runtime expression.
204      */

205     public void setCssClass(String JavaDoc cssClass) {
206         this.cssClass = cssClass;
207     }
208
209     /**
210      * Gets the value of the '<code>class</code>' attribute.
211      * May be a runtime expression.
212      */

213     protected String JavaDoc getCssClass() {
214         return this.cssClass;
215     }
216
217     /**
218      * The CSS class to use when the field bound to a particular tag has errors.
219      * May be a runtime expression.
220      */

221     public void setCssErrorClass(String JavaDoc cssErrorClass) {
222         this.cssErrorClass = cssErrorClass;
223     }
224
225     /**
226      * The CSS class to use when the field bound to a particular tag has errors.
227      * May be a runtime expression.
228      */

229     protected String JavaDoc getCssErrorClass() {
230         return this.cssErrorClass;
231     }
232
233     /**
234      * Sets the value of the '<code>style</code>' attribute.
235      * May be a runtime expression.
236      */

237     public void setCssStyle(String JavaDoc cssStyle) {
238         this.cssStyle = cssStyle;
239     }
240
241     /**
242      * Gets the value of the '<code>style</code>' attribute.
243      * May be a runtime expression.
244      */

245     protected String JavaDoc getCssStyle() {
246         return this.cssStyle;
247     }
248
249     /**
250      * Sets the value of the '<code>lang</code>' attribute.
251      * May be a runtime expression.
252      */

253     public void setLang(String JavaDoc lang) {
254         this.lang = lang;
255     }
256
257     /**
258      * Gets the value of the '<code>lang</code>' attribute.
259      * May be a runtime expression.
260      */

261     protected String JavaDoc getLang() {
262         return this.lang;
263     }
264
265     /**
266      * Sets the value of the '<code>title</code>' attribute.
267      * May be a runtime expression.
268      */

269     public void setTitle(String JavaDoc title) {
270         this.title = title;
271     }
272
273     /**
274      * Gets the value of the '<code>title</code>' attribute.
275      * May be a runtime expression.
276      */

277     protected String JavaDoc getTitle() {
278         return this.title;
279     }
280
281     /**
282      * Sets the value of the '<code>dir</code>' attribute.
283      * May be a runtime expression.
284      */

285     public void setDir(String JavaDoc dir) {
286         this.dir = dir;
287     }
288
289     /**
290      * Gets the value of the '<code>dir</code>' attribute.
291      * May be a runtime expression.
292      */

293     protected String JavaDoc getDir() {
294         return this.dir;
295     }
296
297     /**
298      * Sets the value of the '<code>tabindex</code>' attribute.
299      * May be a runtime expression.
300      */

301     public void setTabindex(String JavaDoc tabindex) {
302         this.tabindex = tabindex;
303     }
304
305     /**
306      * Gets the value of the '<code>tabindex</code>' attribute.
307      * May be a runtime expression.
308      */

309     protected String JavaDoc getTabindex() {
310         return this.tabindex;
311     }
312
313     /**
314      * Sets the value of the '<code>onclick</code>' attribute.
315      * May be a runtime expression.
316      */

317     public void setOnclick(String JavaDoc onclick) {
318         this.onclick = onclick;
319     }
320
321     /**
322      * Gets the value of the '<code>onclick</code>' attribute.
323      * May be a runtime expression.
324      */

325     protected String JavaDoc getOnclick() {
326         return this.onclick;
327     }
328
329     /**
330      * Sets the value of the '<code>ondblclick</code>' attribute.
331      * May be a runtime expression.
332      */

333     public void setOndblclick(String JavaDoc ondblclick) {
334         this.ondblclick = ondblclick;
335     }
336
337     /**
338      * Gets the value of the '<code>ondblclick</code>' attribute.
339      * May be a runtime expression.
340      */

341     protected String JavaDoc getOndblclick() {
342         return this.ondblclick;
343     }
344
345     /**
346      * Sets the value of the '<code>onmousedown</code>' attribute.
347      * May be a runtime expression.
348      */

349     public void setOnmousedown(String JavaDoc onmousedown) {
350         this.onmousedown = onmousedown;
351     }
352
353     /**
354      * Gets the value of the '<code>onmousedown</code>' attribute.
355      * May be a runtime expression.
356      */

357     protected String JavaDoc getOnmousedown() {
358         return this.onmousedown;
359     }
360
361     /**
362      * Sets the value of the '<code>onmouseup</code>' attribute.
363      * May be a runtime expression.
364      */

365     public void setOnmouseup(String JavaDoc onmouseup) {
366         this.onmouseup = onmouseup;
367     }
368
369     /**
370      * Gets the value of the '<code>onmouseup</code>' attribute.
371      * May be a runtime expression.
372      */

373     protected String JavaDoc getOnmouseup() {
374         return this.onmouseup;
375     }
376
377     /**
378      * Sets the value of the '<code>onmouseover</code>' attribute.
379      * May be a runtime expression.
380      */

381     public void setOnmouseover(String JavaDoc onmouseover) {
382         this.onmouseover = onmouseover;
383     }
384
385     /**
386      * Gets the value of the '<code>onmouseover</code>' attribute.
387      * May be a runtime expression.
388      */

389     protected String JavaDoc getOnmouseover() {
390         return this.onmouseover;
391     }
392
393     /**
394      * Sets the value of the '<code>onmousemove</code>' attribute.
395      * May be a runtime expression.
396      */

397     public void setOnmousemove(String JavaDoc onmousemove) {
398         this.onmousemove = onmousemove;
399     }
400
401     /**
402      * Gets the value of the '<code>onmousemove</code>' attribute.
403      * May be a runtime expression.
404      */

405     protected String JavaDoc getOnmousemove() {
406         return this.onmousemove;
407     }
408
409     /**
410      * Sets the value of the '<code>onmouseout</code>' attribute.
411      * May be a runtime expression.
412      */

413     public void setOnmouseout(String JavaDoc onmouseout) {
414         this.onmouseout = onmouseout;
415     }
416     /**
417      * Gets the value of the '<code>onmouseout</code>' attribute.
418      * May be a runtime expression.
419      */

420     protected String JavaDoc getOnmouseout() {
421         return this.onmouseout;
422     }
423
424     /**
425      * Sets the value of the '<code>onkeypress</code>' attribute.
426      * May be a runtime expression.
427      */

428     public void setOnkeypress(String JavaDoc onkeypress) {
429         this.onkeypress = onkeypress;
430     }
431
432     /**
433      * Gets the value of the '<code>onkeypress</code>' attribute.
434      * May be a runtime expression.
435      */

436     protected String JavaDoc getOnkeypress() {
437         return this.onkeypress;
438     }
439
440     /**
441      * Sets the value of the '<code>onkeyup</code>' attribute.
442      * May be a runtime expression.
443      */

444     public void setOnkeyup(String JavaDoc onkeyup) {
445         this.onkeyup = onkeyup;
446     }
447
448     /**
449      * Gets the value of the '<code>onkeyup</code>' attribute.
450      * May be a runtime expression.
451      */

452     protected String JavaDoc getOnkeyup() {
453         return this.onkeyup;
454     }
455
456     /**
457      * Sets the value of the '<code>onkeydown</code>' attribute.
458      * May be a runtime expression.
459      */

460     public void setOnkeydown(String JavaDoc onkeydown) {
461         this.onkeydown = onkeydown;
462     }
463
464     /**
465      * Gets the value of the '<code>onkeydown</code>' attribute.
466      * May be a runtime expression.
467      */

468     protected String JavaDoc getOnkeydown() {
469         return this.onkeydown;
470     }
471
472
473     /**
474      * Writes the default attributes configured via this base class to the supplied {@link TagWriter}.
475      * Subclasses should call this when they want the base attribute set to be written to the output.
476      */

477     protected void writeDefaultAttributes(TagWriter tagWriter) throws JspException JavaDoc {
478         super.writeDefaultAttributes(tagWriter);
479         tagWriter.writeOptionalAttributeValue(CLASS_ATTRIBUTE, resolveCssClass());
480         tagWriter.writeOptionalAttributeValue(STYLE_ATTRIBUTE, ObjectUtils.getDisplayString(evaluate("cssStyle", getCssStyle())));
481         writeOptionalAttribute(tagWriter, LANG_ATTRIBUTE, getLang());
482         writeOptionalAttribute(tagWriter, TITLE_ATTRIBUTE, getTitle());
483         writeOptionalAttribute(tagWriter, DIR_ATTRIBUTE, getDir());
484         writeOptionalAttribute(tagWriter, TABINDEX_ATTRIBUTE, getTabindex());
485         writeOptionalAttribute(tagWriter, ONCLICK_ATTRIBUTE, getOnclick());
486         writeOptionalAttribute(tagWriter, ONDBLCLICK_ATTRIBUTE, getOndblclick());
487         writeOptionalAttribute(tagWriter, ONMOUSEDOWN_ATTRIBUTE, getOnmousedown());
488         writeOptionalAttribute(tagWriter, ONMOUSEUP_ATTRIBUTE, getOnmouseup());
489         writeOptionalAttribute(tagWriter, ONMOUSEOVER_ATTRIBUTE, getOnmouseover());
490         writeOptionalAttribute(tagWriter, ONMOUSEMOVE_ATTRIBUTE, getOnmousemove());
491         writeOptionalAttribute(tagWriter, ONMOUSEOUT_ATTRIBUTE, getOnmouseout());
492         writeOptionalAttribute(tagWriter, ONKEYPRESS_ATTRIBUTE, getOnkeypress());
493         writeOptionalAttribute(tagWriter, ONKEYUP_ATTRIBUTE, getOnkeyup());
494         writeOptionalAttribute(tagWriter, ONKEYDOWN_ATTRIBUTE, getOnkeydown());
495     }
496
497     /**
498      * Gets the appropriate CSS class to use based on the state of the current
499      * {@link org.springframework.web.servlet.support.BindStatus} object.
500      */

501     protected String JavaDoc resolveCssClass() throws JspException JavaDoc {
502         if (getBindStatus().isError() && StringUtils.hasText(getCssErrorClass())) {
503             return ObjectUtils.getDisplayString(evaluate("cssErrorClass", getCssErrorClass()));
504         }
505         else {
506             return ObjectUtils.getDisplayString(evaluate("cssClass", getCssClass()));
507         }
508     }
509 }
510
Popular Tags