View Javadoc

1   /*
2    * $Id: TextareaTag.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.taglib.TagUtils;
21  
22  import javax.servlet.jsp.JspException;
23  
24  /***
25   * Custom tag for input fields of type "textarea".
26   *
27   * @version $Rev: 376841 $ $Date: 2005-04-06 02:37:00 -0400 (Wed, 06 Apr 2005)
28   *          $
29   */
30  public class TextareaTag extends BaseInputTag {
31      // ----------------------------------------------------- Constructor
32      public TextareaTag() {
33          super();
34          doReadonly = true;
35      }
36  
37      // --------------------------------------------------------- Public Methods
38  
39      /***
40       * Generate the required input tag. Support for indexed since Struts 1.1
41       *
42       * @throws JspException if a JSP exception has occurred
43       */
44      public int doStartTag() throws JspException {
45          TagUtils.getInstance().write(pageContext, this.renderTextareaElement());
46  
47          return (EVAL_BODY_TAG);
48      }
49  
50      /***
51       * Generate an HTML <textarea> tag.
52       *
53       * @throws JspException
54       * @since Struts 1.1
55       */
56      protected String renderTextareaElement()
57          throws JspException {
58          StringBuffer results = new StringBuffer("<textarea");
59  
60          prepareAttribute(results, "name", prepareName());
61          prepareAttribute(results, "accesskey", getAccesskey());
62          prepareAttribute(results, "tabindex", getTabindex());
63          prepareAttribute(results, "cols", getCols());
64          prepareAttribute(results, "rows", getRows());
65          results.append(prepareEventHandlers());
66          results.append(prepareStyles());
67          prepareOtherAttributes(results);
68          results.append(">");
69  
70          results.append(this.renderData());
71  
72          results.append("</textarea>");
73  
74          return results.toString();
75      }
76  
77      /***
78       * Renders the value displayed in the &lt;textarea&gt; tag.
79       *
80       * @throws JspException
81       * @since Struts 1.1
82       */
83      protected String renderData()
84          throws JspException {
85          String data = this.value;
86  
87          if (data == null) {
88              data = this.lookupProperty(this.name, this.property);
89          }
90  
91          return (data == null) ? "" : TagUtils.getInstance().filter(data);
92      }
93  
94      /***
95       * Release any acquired resources.
96       */
97      public void release() {
98          super.release();
99          name = Constants.BEAN_KEY;
100     }
101 }