View Javadoc

1   /*
2    * $Id: TextField.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 an HTML input field of type text</p>
34   * <!-- END SNIPPET: javadoc -->
35   *
36   * <p/> <b>Examples</b>
37   * <p/>
38   * <!-- START SNIPPET: exdescription -->
39   * In this example, a text control for the "user" property is rendered. The label is also retrieved from a ResourceBundle via the key attribute.
40   * <!-- END SNIPPET: exdescription -->
41   * <pre>
42   * <!-- START SNIPPET: example -->
43   * &lt;s:textfield key="user" /&gt;
44   * <!-- END SNIPPET: example -->
45   * </pre>
46   *
47   * <pre>
48   * <!-- START SNIPPET: example2 -->
49   * &lt;s:textfield name="user" label="User Name" /&gt;
50   * <!-- END SNIPPET: example -->
51   * </pre>
52  
53   */
54  @StrutsTag(name="textfield", tldTagClass="org.apache.struts2.views.jsp.ui.TextFieldTag", description="Render an HTML input field of type text")
55  public class TextField extends UIBean {
56      /***
57       * The name of the default template for the TextFieldTag
58       */
59      final public static String TEMPLATE = "text";
60  
61  
62      protected String maxlength;
63      protected String readonly;
64      protected String size;
65  
66      public TextField(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
67          super(stack, request, response);
68      }
69  
70      protected String getDefaultTemplate() {
71          return TEMPLATE;
72      }
73  
74      protected void evaluateExtraParams() {
75          super.evaluateExtraParams();
76  
77          if (size != null) {
78              addParameter("size", findString(size));
79          }
80  
81          if (maxlength != null) {
82              addParameter("maxlength", findString(maxlength));
83          }
84  
85          if (readonly != null) {
86              addParameter("readonly", findValue(readonly, Boolean.class));
87          }
88      }
89  
90      @StrutsTagAttribute(description="HTML maxlength attribute", type="Integer")
91      public void setMaxlength(String maxlength) {
92          this.maxlength = maxlength;
93      }
94  
95      @StrutsTagAttribute(description="Deprecated. Use maxlength instead.", type="Integer")
96      public void setMaxLength(String maxlength) {
97          this.maxlength = maxlength;
98      }
99  
100     @StrutsTagAttribute(description="Whether the input is readonly", type="Boolean", defaultValue="false")
101     public void setReadonly(String readonly) {
102         this.readonly = readonly;
103     }
104 
105     @StrutsTagAttribute(description="HTML size attribute",  type="Integer")
106     public void setSize(String size) {
107         this.size = size;
108     }
109 }