KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > DbBaseInputTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbBaseInputTag.java,v 1.30 2004/08/18 12:26:05 hkollmann Exp $
3  * $Revision: 1.30 $
4  * $Date: 2004/08/18 12:26:05 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.dbforms.event.WebEvent;
27 import org.dbforms.event.eventtype.EventType;
28
29 import org.dbforms.util.Util;
30
31 import java.util.Vector JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.jsp.JspException JavaDoc;
35
36
37
38 /**
39  * Abstract base class for the various input tags. original author Craig R.
40  * McClanahan original author Don Clasen,
41  *
42  * @author Joachim Peer (modified this class for DbForms-Project)
43  */

44 public abstract class DbBaseInputTag extends DbBaseHandlerTag {
45    /**
46     * The number of character columns for this field, or negative for no limit.
47     */

48    private String JavaDoc cols = null;
49
50    /** DOCUMENT ME! */
51    private java.lang.String JavaDoc hidden = "false";
52
53    /** The maximum number of characters allowed, or negative for no limit. */
54    private String JavaDoc maxlength = null;
55
56    /** DOCUMENT ME! */
57    private java.lang.String JavaDoc overrideValue;
58
59    /** The number of rows for this field, or negative for no limit. */
60    private String JavaDoc rows = null;
61
62    /**
63     * Set the number of columns for this field.
64     *
65     * @param cols The new number of columns
66     */

67    public void setCols(String JavaDoc cols) {
68       this.cols = cols;
69    }
70
71
72    // ------------------------------------------------------------- Properties
73

74    /**
75     * Return the number of columns for this field.
76     *
77     * @return DOCUMENT ME!
78     */

79    public String JavaDoc getCols() {
80       return (this.cols);
81    }
82
83
84    /**
85     * Insert the method's description here. Creation date: (2001-06-26
86     * 16:19:01)
87     *
88     * @param newHidden java.lang.String
89     */

90    public void setHidden(java.lang.String JavaDoc newHidden) {
91       hidden = newHidden;
92    }
93
94
95    /**
96     * Set the maximum length allowed.
97     *
98     * @param maxlength The new maximum length
99     */

100    public void setMaxlength(String JavaDoc maxlength) {
101       this.maxlength = maxlength;
102    }
103
104
105    /**
106     * Return the maximum length allowed.
107     *
108     * @return DOCUMENT ME!
109     */

110    public String JavaDoc getMaxlength() {
111       return (this.maxlength);
112    }
113
114
115    /**
116     * Insert the method's description here. Creation date: (2001-06-27
117     * 17:44:16)
118     *
119     * @param newOverrideValue java.lang.String
120     */

121    public void setOverrideValue(java.lang.String JavaDoc newOverrideValue) {
122       overrideValue = newOverrideValue;
123    }
124
125
126    /**
127     * Insert the method's description here. Creation date: (2001-06-27
128     * 17:44:16)
129     *
130     * @return java.lang.String
131     */

132    public java.lang.String JavaDoc getOverrideValue() {
133       return overrideValue;
134    }
135
136
137    /**
138     * Set the number of rows for this field.
139     *
140     * @param rows The new number of rows
141     */

142    public void setRows(String JavaDoc rows) {
143       this.rows = rows;
144    }
145
146
147    /**
148     * Return the number of rows for this field.
149     *
150     * @return DOCUMENT ME!
151     */

152    public String JavaDoc getRows() {
153       return (this.rows);
154    }
155
156
157    /**
158     * Set the size of this field (synonym for <code>setCols()</code>).
159     *
160     * @param size The new size
161     */

162    public void setSize(String JavaDoc size) {
163       setCols(size);
164    }
165
166
167    /**
168     * Return the size of this field (synonym for <code>getCols()</code>).
169     *
170     * @return DOCUMENT ME!
171     */

172    public String JavaDoc getSize() {
173       return (getCols());
174    }
175
176
177    /**
178     * Process the end of this tag. The default implementation does nothing.
179     *
180     * @return DOCUMENT ME!
181     *
182     * @exception JspException if a JSP exception has occurred
183     */

184    public int doEndTag() throws JspException JavaDoc {
185       return EVAL_PAGE;
186    }
187
188
189    /**
190     * DOCUMENT ME!
191     */

192    public void doFinally() {
193       cols = null;
194       maxlength = null;
195       rows = null;
196       super.doFinally();
197    }
198
199
200    // --------------------------------------------------------- Public Methods
201

202    /**
203     * Process the start of this tag. The default implementation does nothing.
204     *
205     * @return DOCUMENT ME!
206     *
207     * @exception JspException if a JSP exception has occurred
208     */

209    public int doStartTag() throws JspException JavaDoc {
210       if (hasReadOnlySet() || getParentForm()
211                                        .hasReadOnlySet()) {
212          String JavaDoc onFocus = (getOnFocus() != null) ? getOnFocus()
213                                                  : "";
214
215          if (onFocus.lastIndexOf(";") != (onFocus.length() - 1)) {
216             onFocus += ";"; // be sure javascript end with ";"
217
}
218
219          setOnFocus(onFocus + "this.blur();");
220       }
221
222       return EVAL_BODY_BUFFERED;
223    }
224
225
226    /**
227     * Insert the method's description here. Creation date: (2001-06-26
228     * 16:19:01)
229     *
230     * @return java.lang.String
231     */

232    public boolean hasHiddenSet() {
233       return Util.getTrue(hidden);
234    }
235
236
237    /**
238     * gets the formfield value
239     *
240     * @return String
241     */

242    protected String JavaDoc getFormFieldValue() {
243       String JavaDoc res;
244
245       /* If the overrideValue attribute has been set, use its value instead of the one
246          retrieved from the database. This mechanism can be used to set an initial default
247          value for a given field. */

248       HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) this.pageContext
249                                    .getRequest();
250       Vector JavaDoc errors = (Vector JavaDoc) request.getAttribute("errors");
251       WebEvent we = getParentForm()
252                                      .getWebEvent();
253
254       if ((this.getOverrideValue() != null)
255                 && !((getParentForm()
256                                .hasRedisplayFieldsOnErrorSet()
257                 && (errors != null) && (errors.size() > 0))
258                 || ((we != null)
259                 && (we.getType().equals(EventType.EVENT_NAVIGATION_RELOAD))))) {
260          res = getOverrideValue();
261       } else //If the redisplayFieldsOnError attribute is set and we are in error mode, forget override!
262
{
263          res = super.getFormFieldValue();
264       }
265
266       return res;
267    }
268
269
270    /**
271     * DOCUMENT ME!
272     *
273     * @return DOCUMENT ME!
274     */

275    protected String JavaDoc prepareKeys() {
276       StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
277
278       if (getAccessKey() != null) {
279          tagBuf.append(" accesskey=\"");
280          tagBuf.append(getAccessKey());
281          tagBuf.append("\"");
282       }
283
284       if (getTabIndex() != null) {
285          tagBuf.append(" tabindex=\"");
286          tagBuf.append(getTabIndex());
287          tagBuf.append("\"");
288       }
289
290       return tagBuf.toString();
291    }
292
293
294    /**
295     * DOCUMENT ME!
296     *
297     * @return DOCUMENT ME!
298     */

299    protected String JavaDoc prepareName() {
300       StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
301       tagBuf.append("name=\"");
302       tagBuf.append(getFormFieldName());
303       tagBuf.append("\"");
304
305       return tagBuf.toString();
306    }
307
308
309    /**
310     * DOCUMENT ME!
311     *
312     * @return DOCUMENT ME!
313     */

314    protected String JavaDoc prepareSize() {
315       StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
316
317       if (getMaxlength() != null) {
318          tagBuf.append(" maxlength=\"");
319          tagBuf.append(getMaxlength());
320          tagBuf.append("\"");
321       }
322
323       if (getCols() != null) {
324          tagBuf.append(" size=\"");
325          tagBuf.append(getCols());
326          tagBuf.append("\"");
327       }
328
329       return tagBuf.toString();
330    }
331
332
333    /**
334     * DOCUMENT ME!
335     *
336     * @return DOCUMENT ME!
337     */

338    protected String JavaDoc prepareType() {
339       return hasHiddenSet() ? "type=\"hidden\" "
340                             : "type=\"text\" ";
341    }
342
343
344    /**
345     * DOCUMENT ME!
346     *
347     * @return DOCUMENT ME!
348     */

349    protected String JavaDoc prepareValue() {
350       StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc();
351       tagBuf.append(" value=\"");
352       tagBuf.append(escapeHTML(getFormFieldValue()));
353       tagBuf.append("\" ");
354
355       return tagBuf.toString();
356    }
357
358
359    /**
360     * writes out all hidden fields for the input fields
361     */

362    protected void writeOutSpecialValues() throws JspException JavaDoc {
363       super.writeOutSpecialValues();
364
365       try {
366          pageContext.getOut()
367                     .write(renderPatternHtmlInputField());
368       } catch (java.io.IOException JavaDoc ioe) {
369          throw new JspException JavaDoc("IO Error: " + ioe.getMessage());
370       }
371    }
372 }
373
Popular Tags