View Javadoc

1   /*
2    * $Id: InputTag.java 130 2004-11-28 13:00:44Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.taglib.form;
24  
25  import java.io.IOException;
26  
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * Base implementation of input form control tags.
31   *
32   * @author  Jose M. Palomar
33   * @version $Revision: 130 $
34   */
35  public abstract class InputTag extends BaseControlTag {
36  
37      // Fields
38      /**
39       * Input type.
40       */
41      private String type;
42  
43      // Constructors
44      /**
45       * Creates a new <code>InputTag</code> object.
46       */
47      public InputTag() {
48      }
49  
50      /**
51       * Creates a new <code>InputTag</code> object of given type.
52       *
53       * @param type String input type.
54       */
55      protected InputTag(String type) {
56          this.type = type;
57      }
58  
59      // Methods
60      /**
61       * Process the start tag for this instance.
62       *
63       * @return int SKIP^_BODY.
64       * @throws JspException if somethign goes wrong during processing.
65       * @see javax.servlet.jsp.tagext.Tag#doStartTag()
66       */
67      public int doStartTag() throws JspException {
68  
69          try {
70              pageContext.getOut().print(renderInputElement());
71          }
72          catch (IOException ioe) {
73              // Bad luck
74          }
75  
76          return SKIP_BODY;
77  
78      }
79  
80      // Renderer
81      /**
82       * Renders input tag.
83       *
84       * @return String a string with rendered input tag.
85       */
86      public final String renderInputElement() {
87  
88          StringBuffer element = new StringBuffer();
89  
90          element.append("<input");
91  
92          element.append(baseAttributes());
93  
94          element.append(" type=\"");
95          element.append(type);
96          element.append("\"");
97  
98          element.append(controlName());
99          element.append(controlValue());
100         element.append(inputAttributes());
101         element.append(controlAttributes());
102         element.append(controlEvents());
103         element.append(intrinsicEvents());
104 
105         element.append(">");
106 
107         return element.toString();
108 
109     }
110 
111     /**
112      * Renders a string with values of input attributes.
113      *
114      * @return String an empty string.
115      */
116     public String inputAttributes() {
117         return "";
118     }
119 
120 }