View Javadoc

    1   /*
    2    * $Id: TextareaTag.java 471754 2006-11-06 14:55:09Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21  package org.apache.struts.taglib.html;
    22
    23  import org.apache.struts.taglib.TagUtils;
    24
    25  import javax.servlet.jsp.JspException;
    26
    27  /**
    28   * Custom tag for input fields of type "textarea".
    29   *
    30   * @version $Rev: 471754 $ $Date: 2005-04-06 02:37:00 -0400 (Wed, 06 Apr 2005)
    31   *          $
    32   */
    33  public class TextareaTag extends BaseInputTag {
    34      // ----------------------------------------------------- Constructor
    35      public TextareaTag() {
    36          super();
    37          doReadonly = true;
    38      }
    39
    40      // --------------------------------------------------------- Public Methods
    41
    42      /**
    43       * Generate the required input tag. Support for indexed since Struts 1.1
    44       *
    45       * @throws JspException if a JSP exception has occurred
    46       */
    47      public int doStartTag() throws JspException {
    48          TagUtils.getInstance().write(pageContext, this.renderTextareaElement());
    49
    50          return (EVAL_BODY_TAG);
    51      }
    52
    53      /**
    54       * Generate an HTML &lt;textarea&gt; tag.
    55       *
    56       * @throws JspException
    57       * @since Struts 1.1
    58       */
    59      protected String renderTextareaElement()
    60          throws JspException {
    61          StringBuffer results = new StringBuffer("<textarea");
    62
    63          prepareAttribute(results, "name", prepareName());
    64          prepareAttribute(results, "accesskey", getAccesskey());
    65          prepareAttribute(results, "tabindex", getTabindex());
    66          prepareAttribute(results, "cols", getCols());
    67          prepareAttribute(results, "rows", getRows());
    68          results.append(prepareEventHandlers());
    69          results.append(prepareStyles());
    70          prepareOtherAttributes(results);
    71          results.append(">");
    72
    73          results.append(this.renderData());
    74
    75          results.append("</textarea>");
    76
    77          return results.toString();
    78      }
    79
    80      /**
    81       * Renders the value displayed in the &lt;textarea&gt; tag.
    82       *
    83       * @throws JspException
    84       * @since Struts 1.1
    85       */
    86      protected String renderData()
    87          throws JspException {
    88          String data = this.value;
    89
    90          if (data == null) {
    91              data = this.lookupProperty(this.name, this.property);
    92          }
    93
    94          return (data == null) ? "" : TagUtils.getInstance().filter(data);
    95      }
    96
    97      /**
    98       * Release any acquired resources.
    99       */
    100     public void release() {
    101         super.release();
    102         name = Constants.BEAN_KEY;
    103     }
    104 }