View Javadoc

1   /*
2    * $Id: TextAreaTag.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   * Implementation of textarea form control tag.
31   *
32   * @author  Jose M. Palomar
33   * @version $Revision: 130 $
34   * @todo The value of a textarea is text between tags.
35   */
36  public final class TextAreaTag extends BaseControlTag {
37  
38      // Fields
39      /**
40       * <code>rows</code> attribute.
41       */
42      private String rows;
43      /**
44       * <code>cols</code> attribute.
45       */
46      private String cols;
47  
48      // Constructors
49      /**
50       * Creates a new <code>TextAreaTag</code> object.
51       */
52      public TextAreaTag() {
53      }
54  
55      // Methods
56      /**
57       * Process the start tag for this instance.
58       *
59       * @return int EVAL_BODY_INCLUDE.
60       * @throws JspException if somethign goes wrong during processing.
61       * @see javax.servlet.jsp.tagext.Tag#doStartTag()
62       */
63      public int doStartTag() throws JspException {
64  
65          try {
66              pageContext.getOut().print(renderTextAreaStartElement());
67          }
68          catch (IOException ioe) {
69              // Bad luck
70          }
71  
72          return EVAL_BODY_INCLUDE;
73  
74      }
75  
76      /**
77       * Process the end tag for this instance.
78       *
79       * @return int EVAL_PAGE.
80       * @throws JspException if somethign goes wrong during processing.
81       * @see javax.servlet.jsp.tagext.Tag#doEndTag()
82       */
83      public int doEndTag() throws JspException {
84  
85          try {
86              pageContext.getOut().print(renderTextAreaEndElement());
87          }
88          catch (IOException ioe) {
89              // Bad luck
90          }
91  
92          return EVAL_PAGE;
93      }
94  
95      // Renderer
96      /**
97       * Renders textarea start tag.
98       *
99       * @return String a string containing rendered textarea start tag.
100      */
101     public String renderTextAreaStartElement() {
102 
103         StringBuffer element = new StringBuffer();
104 
105         element.append("<textarea");
106 
107         element.append(baseAttributes());
108         element.append(controlName());
109         element.append(controlAttributes());
110 
111         if (rows != null) {
112             element.append(" rows=\"");
113             element.append(rows);
114             element.append("\"");
115         }
116 
117         if (cols != null) {
118             element.append(" cols=\"");
119             element.append(cols);
120             element.append("\"");
121         }
122 
123         element.append(controlEvents());
124         element.append(intrinsicEvents());
125 
126         element.append(">");
127 
128         return element.toString();
129 
130     }
131 
132     /**
133      * Renders textarea end tag.
134      *
135      * @return String a string containing rendered textarea end tag.
136      */
137     public String renderTextAreaEndElement() {
138         return "</textarea>";
139     }
140 
141     // Attributes
142     /**
143      * Sets <code>cols</code> attribute value.
144      *
145      * @param cols String <code>cols</code> attribute value.
146      */
147     public void setCols(String cols) {
148         this.cols = cols;
149     }
150 
151     /**
152      * Sets <code>rows</code> attribute value.
153      *
154      * @param rows String <code>rows</code> attribute value.
155      */
156     public void setRows(String rows) {
157         this.rows = rows;
158     }
159 
160     /**
161      * Called on a Tag handler to release state.
162      *
163      * @see javax.servlet.jsp.tagext.Tag#release()
164      */
165     public void release() {
166 
167         super.release();
168 
169         this.rows = null;
170         this.cols = null;
171 
172     }
173 
174 }