View Javadoc

1   /*
2    * $Id: TextField.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 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.struts2.components;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import com.opensymphony.xwork2.util.ValueStack;
24  
25  /***
26   * <!-- START SNIPPET: javadoc -->
27   * Render an HTML input field of type text</p>
28   * <!-- END SNIPPET: javadoc -->
29   *
30   * <p/> <b>Examples</b>
31   * <p/>
32   * <!-- START SNIPPET: exdescription -->
33   * In this example, a text control is rendered. The label is retrieved from a ResourceBundle by calling
34   * ActionSupport's getText() method.<p/>
35   * <!-- END SNIPPET: exdescription -->
36   * <pre>
37   * <!-- START SNIPPET: example -->
38   * &lt;s:textfield label="%{text('user_name')}" name="user" /&gt;
39   * <!-- END SNIPPET: example -->
40   * </pre>
41   *
42   * @s.tag name="textfield" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ui.TextFieldTag"
43   * description="Render an HTML input field of type text"
44   */
45  public class TextField extends UIBean {
46      /***
47       * The name of the default template for the TextFieldTag
48       */
49      final public static String TEMPLATE = "text";
50  
51  
52      protected String maxlength;
53      protected String readonly;
54      protected String size;
55  
56      public TextField(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
57          super(stack, request, response);
58      }
59  
60      protected String getDefaultTemplate() {
61          return TEMPLATE;
62      }
63  
64      protected void evaluateExtraParams() {
65          super.evaluateExtraParams();
66  
67          if (size != null) {
68              addParameter("size", findString(size));
69          }
70  
71          if (maxlength != null) {
72              addParameter("maxlength", findString(maxlength));
73          }
74  
75          if (readonly != null) {
76              addParameter("readonly", findValue(readonly, Boolean.class));
77          }
78      }
79  
80      /***
81       * HTML maxlength attribute
82       * @s.tagattribute required="false" type="Integer"
83       */
84      public void setMaxlength(String maxlength) {
85          this.maxlength = maxlength;
86      }
87  
88      /***
89       * Deprecated. Use maxlength instead.
90       * @s.tagattribute required="false"
91       */
92      public void setMaxLength(String maxlength) {
93          this.maxlength = maxlength;
94      }
95  
96      /***
97       * Whether the input is readonly
98       * @s.tagattribute required="false" type="Boolean" default="false"
99       */
100     public void setReadonly(String readonly) {
101         this.readonly = readonly;
102     }
103 
104     /***
105      * HTML size attribute
106      * @s.tagattribute required="false" type="Integer"
107      */
108     public void setSize(String size) {
109         this.size = size;
110     }
111 }