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