1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 * <s:textfield label="%{text('user_name')}" name="user" />
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 }