View Javadoc

1   /*
2    * $Id: BaseInputTag.java 471754 2006-11-06 14:55:09Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts.taglib.html;
22  
23  import org.apache.struts.util.MessageResources;
24  
25  import javax.servlet.jsp.JspException;
26  
27  /**
28   * Abstract base class for the various input tags.
29   *
30   * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
31   *          $
32   */
33  public abstract class BaseInputTag extends BaseHandlerTag {
34      /**
35       * The message resources for this package.
36       */
37      protected static MessageResources messages =
38          MessageResources.getMessageResources(Constants.Package
39              + ".LocalStrings");
40  
41      // ----------------------------------------------------- Instance Variables
42  
43      /**
44       * The number of character columns for this field, or negative for no
45       * limit.
46       */
47      protected String cols = null;
48  
49      /**
50       * The maximum number of characters allowed, or negative for no limit.
51       */
52      protected String maxlength = null;
53  
54      /**
55       * The name of the field (and associated property) being processed.
56       */
57      protected String property = null;
58  
59      /**
60       * The number of rows for this field, or negative for no limit.
61       */
62      protected String rows = null;
63  
64      /**
65       * The value for this field, or <code>null</code> to retrieve the
66       * corresponding property from our associated bean.
67       */
68      protected String value = null;
69  
70      /**
71       * The name of the bean containing our underlying property.
72       */
73      protected String name = Constants.BEAN_KEY;
74  
75      // ------------------------------------------------------------- Properties
76      public String getName() {
77          return (this.name);
78      }
79  
80      public void setName(String name) {
81          this.name = name;
82      }
83  
84      /**
85       * Return the number of columns for this field.
86       */
87      public String getCols() {
88          return (this.cols);
89      }
90  
91      /**
92       * Set the number of columns for this field.
93       *
94       * @param cols The new number of columns
95       */
96      public void setCols(String cols) {
97          this.cols = cols;
98      }
99  
100     /**
101      * Return the maximum length allowed.
102      */
103     public String getMaxlength() {
104         return (this.maxlength);
105     }
106 
107     /**
108      * Set the maximum length allowed.
109      *
110      * @param maxlength The new maximum length
111      */
112     public void setMaxlength(String maxlength) {
113         this.maxlength = maxlength;
114     }
115 
116     /**
117      * Return the property name.
118      */
119     public String getProperty() {
120         return (this.property);
121     }
122 
123     /**
124      * Set the property name.
125      *
126      * @param property The new property name
127      */
128     public void setProperty(String property) {
129         this.property = property;
130     }
131 
132     /**
133      * Return the number of rows for this field.
134      */
135     public String getRows() {
136         return (this.rows);
137     }
138 
139     /**
140      * Set the number of rows for this field.
141      *
142      * @param rows The new number of rows
143      */
144     public void setRows(String rows) {
145         this.rows = rows;
146     }
147 
148     /**
149      * Return the size of this field (synonym for <code>getCols()</code>).
150      */
151     public String getSize() {
152         return (getCols());
153     }
154 
155     /**
156      * Set the size of this field (synonym for <code>setCols()</code>).
157      *
158      * @param size The new size
159      */
160     public void setSize(String size) {
161         setCols(size);
162     }
163 
164     /**
165      * Return the field value (if any).
166      */
167     public String getValue() {
168         return (this.value);
169     }
170 
171     /**
172      * Set the field value (if any).
173      *
174      * @param value The new field value, or <code>null</code> to retrieve the
175      *              corresponding property from the bean
176      */
177     public void setValue(String value) {
178         this.value = value;
179     }
180 
181     // --------------------------------------------------------- Public Methods
182 
183     /**
184      * Process the start of this tag.  The default implementation does
185      * nothing.
186      *
187      * @throws JspException if a JSP exception has occurred
188      */
189     public int doStartTag() throws JspException {
190         return (EVAL_BODY_TAG);
191     }
192 
193     /**
194      * Process the end of this tag.  The default implementation does nothing.
195      *
196      * @throws JspException if a JSP exception has occurred
197      */
198     public int doEndTag() throws JspException {
199         return (EVAL_PAGE);
200     }
201 
202     /**
203      * Prepare the name element
204      *
205      * @return The element name.
206      */
207     protected String prepareName()
208         throws JspException {
209         if (property == null) {
210             return null;
211         }
212 
213         // * @since Struts 1.1
214         if (indexed) {
215             StringBuffer results = new StringBuffer();
216 
217             prepareIndex(results, name);
218             results.append(property);
219 
220             return results.toString();
221         }
222 
223         return property;
224     }
225 
226     /**
227      * Release any acquired resources.
228      */
229     public void release() {
230         super.release();
231         name = Constants.BEAN_KEY;
232         cols = null;
233         maxlength = null;
234         property = null;
235         rows = null;
236         value = null;
237     }
238 }