KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > InputTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html;
8
9
10 import javax.servlet.jsp.JspException JavaDoc;
11
12 import com.inversoft.verge.mvc.view.HtmlConstants;
13 import com.inversoft.verge.mvc.view.jsp.JspTools;
14
15
16 /**
17  * This class is the base class for all input tags. It holds
18  * the common attributes such as bean and value.
19  *
20  * @author Brian Pontarelli
21  */

22 public abstract class InputTag extends BaseModelTag {
23
24     private String JavaDoc onfocus;
25     protected String JavaDoc localOnfocus;
26     private String JavaDoc onblur;
27     protected String JavaDoc localOnblur;
28     private String JavaDoc onselect;
29     protected String JavaDoc localOnselect;
30     private String JavaDoc onchange;
31     protected String JavaDoc localOnchange;
32     protected Integer JavaDoc size;
33     protected Integer JavaDoc maxlength;
34     protected Boolean JavaDoc disabled;
35     protected Boolean JavaDoc readonly;
36     private FormTag formParent;
37
38
39     /**
40      * Retrieves the tags disabled attribute
41      *
42      * @return Returns the tags disabled attribute
43      */

44     public Boolean JavaDoc getDisabled() {
45         return disabled;
46     }
47
48     /**
49      * Populates the tags disabled attribute
50      *
51      * @param disabled The value of the tags disabled attribute
52      */

53     public void setDisabled(Boolean JavaDoc disabled) {
54         this.disabled = disabled;
55     }
56
57     /**
58      * Retrieves the tags readonly attribute
59      *
60      * @return Returns the tags readonly attribute
61      */

62     public Boolean JavaDoc getReadonly() {
63         return readonly;
64     }
65
66     /**
67      * Populates the tags readonly attribute
68      *
69      * @param readonly The value of the tags readonly attribute
70      */

71     public void setReadonly(Boolean JavaDoc readonly) {
72         this.readonly = readonly;
73     }
74
75     /**
76      * Retrieves the tags size attribute
77      *
78      * @return Returns the tags size attribute
79      */

80     public Integer JavaDoc getSize() {
81         return size;
82     }
83
84     /**
85      * Populates the tags size attribute
86      *
87      * @param size The value of the tags size attribute
88      */

89     public void setSize(Integer JavaDoc size) {
90         this.size = size;
91     }
92
93     /**
94      * Retrieves the tags maxlength attribute
95      *
96      * @return Returns the tags maxlength attribute
97      */

98     public Integer JavaDoc getMaxlength() {
99         return maxlength;
100     }
101
102     /**
103      * Populates the tags maxlength attribute
104      *
105      * @param maxlength The value of the tags maxlength attribute
106      */

107     public void setMaxlength(Integer JavaDoc maxlength) {
108         this.maxlength = maxlength;
109     }
110
111     /**
112      * Retrieves the tags onfocus attribute
113      *
114      * @return Returns the tags onfocus attribute
115      */

116     public String JavaDoc getOnfocus() {
117         return onfocus;
118     }
119
120     /**
121      * Populates the tags onfocus attribute
122      *
123      * @param onfocus The value of the tags onfocus attribute
124      */

125     public void setOnfocus(String JavaDoc onfocus) {
126         this.onfocus = onfocus;
127     }
128
129     /**
130      * Retrieves the tags onblur attribute
131      *
132      * @return Returns the tags onblur attribute
133      */

134     public String JavaDoc getOnblur() {
135         return onblur;
136     }
137
138     /**
139      * Populates the tags onblur attribute
140      *
141      * @param onblur The value of the tags onblur attribute
142      */

143     public void setOnblur(String JavaDoc onblur) {
144         this.onblur = onblur;
145     }
146
147     /**
148      * Retrieves the tags onselect attribute
149      *
150      * @return Returns the tags onselect attribute
151      */

152     public String JavaDoc getOnselect() {
153         return onselect;
154     }
155
156     /**
157      * Populates the tags onselect attribute
158      *
159      * @param onselect The value of the tags onselect attribute
160      */

161     public void setOnselect(String JavaDoc onselect) {
162         this.onselect = onselect;
163     }
164
165     /**
166      * Retrieves the tags onchange attribute
167      *
168      * @return Returns the tags onchange attribute
169      */

170     public String JavaDoc getOnchange() {
171         return onchange;
172     }
173
174     /**
175      * Populates the tags onchange attribute
176      *
177      * @param onchange The value of the tags onchange attribute
178      */

179     public void setOnchange(String JavaDoc onchange) {
180         this.onchange = onchange;
181     }
182
183     /**
184      * Children should call this method to initialize the input tag. It will
185      * check that the tag is inside a form tag.
186      *
187      * @throws JspException If the input tag is not inside a form tag
188      */

189     protected void initialize() throws JspException JavaDoc {
190         super.initialize();
191
192         // Only initialize the form parent
193
formParent = (FormTag) findAncestorWithClass(this, FormTag.class);
194         if (formParent == null) {
195             throw new JspException JavaDoc("all input tags must be inside a form tag");
196         }
197
198         localOnfocus = onfocus;
199         localOnblur = onblur;
200         localOnselect = onselect;
201         localOnchange = onchange;
202
203         // Expand the attributes if not JSP 2.0+.
204
if (!JspTools.JSP_20) {
205             localOnfocus = (String JavaDoc) JspTools.expand("onfocus", onfocus,
206                 String JavaDoc.class, this, pageContext);
207             localOnblur = (String JavaDoc) JspTools.expand("onblur", onblur,
208                 String JavaDoc.class, this, pageContext);
209             localOnselect = (String JavaDoc) JspTools.expand("onselect", onselect,
210                 String JavaDoc.class, this, pageContext);
211             localOnchange = (String JavaDoc) JspTools.expand("onchange", onchange,
212                 String JavaDoc.class, this, pageContext);
213         }
214
215         if (disabled != null && disabled.booleanValue()) {
216             singleAttrs.add(HtmlConstants.DISABLED);
217         }
218
219         if (readonly != null && readonly.booleanValue()) {
220             singleAttrs.add(HtmlConstants.READONLY);
221         }
222
223         attributes.put(HtmlConstants.SIZE, size);
224         attributes.put(HtmlConstants.MAX_LENGTH, maxlength);
225         attributes.put(HtmlConstants.ON_FOCUS, localOnfocus);
226         attributes.put(HtmlConstants.ON_BLUR, localOnblur);
227         attributes.put(HtmlConstants.ON_SELECT, localOnselect);
228         attributes.put(HtmlConstants.ON_CHANGE, localOnchange);
229     }
230
231     /**
232      * Returns the parent form tag of this input tag
233      *
234      * @return The parent form tag
235      */

236     protected FormTag getFormParent() {
237         return formParent;
238     }
239
240     /**
241      * Since a single instance of the Tag may be used, we need to reset any state
242      * that is internally dependent such as the hasValue boolean and the value
243      * object (done by calling setValue(null)).
244      *
245      * @see javax.servlet.jsp.tagext.Tag#release()
246      */

247     public void release() {
248         super.release();
249         setOnfocus(null);
250         setOnblur(null);
251         setOnselect(null);
252         setOnchange(null);
253         setSize(null);
254         setMaxlength(null);
255         setDisabled(null);
256         setReadonly(null);
257         formParent = null;
258     }
259 }
260
Popular Tags