View Javadoc

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