View Javadoc

    1   /*
    2    * $Id: Reset.java 497654 2007-01-19 00:21:57Z rgielen $
    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.struts2.components;
    22
    23  import javax.servlet.http.HttpServletRequest;
    24  import javax.servlet.http.HttpServletResponse;
    25
    26  import org.apache.struts2.views.annotations.StrutsTag;
    27  import org.apache.struts2.views.annotations.StrutsTagAttribute;
    28
    29  import com.opensymphony.xwork2.util.ValueStack;
    30
    31  /***
    32   * <!-- START SNIPPET: javadoc -->
    33   * Render a reset button. The reset tag is used together with the form tag to provide form resetting.
    34   * The reset can have two different types of rendering:
    35   * <ul>
    36   * <li>input: renders as html &lt;input type="reset"...&gt;</li>
    37   * <li>button: renders as html &lt;button type="reset"...&gt;</li>
    38   * </ul>
    39   * Please note that the button type has advantages by adding the possibility to seperate the submitted value from the
    40   * text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0
    41   * <!-- END SNIPPET: javadoc -->
    42   *
    43   * <p/> <b>Examples</b>
    44   *
    45   * <pre>
    46   * <!-- START SNIPPET: example -->
    47   * &lt;s:reset value="Reset" /&gt;
    48   * <!-- END SNIPPET: example -->
    49   * </pre>
    50   *
    51   * <pre>
    52   * <!-- START SNIPPET: example2 -->
    53   * Render an button reset:
    54   * &lt;s:reset type="button" key="reset"/&gt;
    55   * <!-- END SNIPPET: example2 -->
    56   * </pre>
    57   *
    58   */
    59  @StrutsTag(name="reset", tldTagClass="org.apache.struts2.views.jsp.ui.ResetTag", description="Render a reset button")
    60  public class Reset extends FormButton {
    61      final public static String TEMPLATE = "reset";
    62
    63      protected String action;
    64      protected String method;
    65      protected String align;
    66      protected String type;
    67
    68      public Reset(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
    69          super(stack, request, response);
    70      }
    71
    72      protected String getDefaultTemplate() {
    73          return Reset.TEMPLATE;
    74      }
    75
    76      public void evaluateParams() {
    77
    78          if ((key == null) && (value == null)) {
    79              value = "Reset";
    80          }
    81
    82          if (((key != null)) && (value == null)) {
    83              this.value = "%{getText('"+key +"')}";
    84          }
    85
    86          super.evaluateParams();
    87
    88      }
    89
    90      /***
    91       * Indicate whether the concrete button supports the type "image".
    92       *
    93       * @return <tt>false</tt> to indicate type image is supported.
    94       */
    95      protected boolean supportsImageType() {
    96          return false;
    97      }
    98
    99      @StrutsTagAttribute(description="Supply a reset button text apart from reset value. Will have no effect for " +
    100                 "<i>input</i> type reset, since button text will always be the value parameter.")
    101     public void setLabel(String label) {
    102         super.setLabel(label);
    103     }
    104
    105 }