View Javadoc

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