KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2007 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 /**
22  * Data-binding-aware JSP tag for rendering an HTML '<code>input</code>'
23  * element with a '<code>type</code>' of '<code>text</code>'.
24  *
25  * @author Rob Harrop
26  * @author Juergen Hoeller
27  * @since 2.0
28  */

29 public class InputTag extends AbstractHtmlInputElementTag {
30
31     /**
32      * The name of the '<code>maxlength</code>' attribute.
33      */

34     public static final String JavaDoc MAXLENGTH_ATTRIBUTE = "maxlength";
35
36     /**
37      * The name of the '<code>alt</code>' attribute.
38      */

39     public static final String JavaDoc ALT_ATTRIBUTE = "alt";
40
41     /**
42      * The name of the '<code>onselect</code>' attribute.
43      */

44     public static final String JavaDoc ONSELECT_ATTRIBUTE = "onselect";
45
46     /**
47      * The name of the '<code>size</code>' attribute.
48      */

49     public static final String JavaDoc SIZE_ATTRIBUTE = "size";
50
51     /**
52      * The name of the '<code>readonly</code>' attribute.
53      */

54     public static final String JavaDoc READONLY_ATTRIBUTE = "readonly";
55
56
57     /**
58      * The value of the '<code>maxlength</code>' attribute.
59      */

60     private String JavaDoc maxlength;
61
62     /**
63      * The value of the '<code>alt</code>' attribute.
64      */

65     private String JavaDoc alt;
66
67     /**
68      * The value of the '<code>onselect</code>' attribute.
69      */

70     private String JavaDoc onselect;
71
72     /**
73      * The value of the '<code>size</code>' attribute.
74      */

75     private String JavaDoc size;
76
77     /**
78      * The value of the '<code>readonly</code>' attribute.
79      */

80     private String JavaDoc readonly;
81
82
83     /**
84      * Set the value of the '<code>maxlength</code>' attribute.
85      * May be a runtime expression.
86      */

87     public void setMaxlength(String JavaDoc maxlength) {
88         this.maxlength = maxlength;
89     }
90
91     /**
92      * Get the value of the '<code>maxlength</code>' attribute.
93      */

94     protected String JavaDoc getMaxlength() {
95         return this.maxlength;
96     }
97
98     /**
99      * Set the value of the '<code>alt</code>' attribute.
100      * May be a runtime expression.
101      */

102     public void setAlt(String JavaDoc alt) {
103         this.alt = alt;
104     }
105
106     /**
107      * Get the value of the '<code>alt</code>' attribute.
108      */

109     protected String JavaDoc getAlt() {
110         return this.alt;
111     }
112
113     /**
114      * Set the value of the '<code>onselect</code>' attribute.
115      * May be a runtime expression.
116      */

117     public void setOnselect(String JavaDoc onselect) {
118         this.onselect = onselect;
119     }
120
121     /**
122      * Get the value of the '<code>onselect</code>' attribute.
123      */

124     protected String JavaDoc getOnselect() {
125         return this.onselect;
126     }
127
128     /**
129      * Set the value of the '<code>size</code>' attribute.
130      * May be a runtime expression.
131      */

132     public void setSize(String JavaDoc size) {
133         this.size = size;
134     }
135
136     /**
137      * Get the value of the '<code>size</code>' attribute.
138      */

139     protected String JavaDoc getSize() {
140         return this.size;
141     }
142
143     /**
144      * Set the value of the '<code>readonly</code>' attribute.
145      * May be a runtime expression.
146      */

147     public void setReadonly(String JavaDoc readonly) {
148         this.readonly = readonly;
149     }
150
151     /**
152      * Get the value of the '<code>readonly</code>' attribute.
153      */

154     protected String JavaDoc getReadonly() {
155         return this.readonly;
156     }
157
158     /**
159      * Get the value of the '<code>type</code>' attribute. Subclasses
160      * can override this to change the type of '<code>input</code>' element
161      * rendered. Default value is '<code>text</code>'.
162      */

163     protected String JavaDoc getType() {
164         return "text";
165     }
166
167
168     /**
169      * Writes the '<code>input</code>' tag to the supplied {@link TagWriter}.
170      * Uses the value returned by {@link #getType()} to determine which
171      * type of '<code>input</code>' element to render.
172      */

173     protected int writeTagContent(TagWriter tagWriter) throws JspException JavaDoc {
174         tagWriter.startTag("input");
175         writeDefaultAttributes(tagWriter);
176         tagWriter.writeAttribute("type", getType());
177         writeValue(tagWriter);
178
179         // custom optional attributes
180
writeOptionalAttribute(tagWriter, SIZE_ATTRIBUTE, getSize());
181         writeOptionalAttribute(tagWriter, MAXLENGTH_ATTRIBUTE, getMaxlength());
182         writeOptionalAttribute(tagWriter, ALT_ATTRIBUTE, getAlt());
183         writeOptionalAttribute(tagWriter, ONSELECT_ATTRIBUTE, getOnselect());
184         writeOptionalAttribute(tagWriter, READONLY_ATTRIBUTE, getReadonly());
185         tagWriter.endTag();
186         return EVAL_PAGE;
187     }
188
189     /**
190      * Writes the '<code>value</code>' attribute to the supplied {@link TagWriter}.
191      * Subclasses may choose to override this implementation to control exactly
192      * when the value is written.
193      */

194     protected void writeValue(TagWriter tagWriter) throws JspException JavaDoc {
195         tagWriter.writeAttribute("value", getDisplayString(getBoundValue(), getPropertyEditor()));
196     }
197
198 }
199
Popular Tags