1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 * <s:textfield key="user" />
44 * <!-- END SNIPPET: example -->
45 * </pre>
46 *
47 * <pre>
48 * <!-- START SNIPPET: example2 -->
49 * <s:textfield name="user" label="User Name" />
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 }