1
2
3
4
5 package gboat2.base.view.components;
6
7 import gboat2.base.view.GboatViewUtil;
8
9 import java.util.Calendar;
10 import java.util.Date;
11
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14
15 import org.apache.struts2.views.annotations.StrutsTag;
16 import org.apache.struts2.views.annotations.StrutsTagAttribute;
17
18 import com.opensymphony.xwork2.util.ValueStack;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 @StrutsTag(
34 name="textfield",
35 tldTagClass="gboat2.base.view.jsp.TextFieldTag",
36 description="创建一个输入框",
37 allowDynamicAttributes=true)
38 public class TextField extends org.apache.struts2.components.TextField {
39
40 protected String colspan;
41 protected String groupColumns;
42 protected String labelCssClass;
43 protected String labelCssStyle;
44 protected String helpText;
45 protected String inputPrepend;
46 protected String inputAppend;
47
48 public TextField(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
49 super(stack, request, response);
50 }
51
52 @Override
53 protected void evaluateExtraParams() {
54 super.evaluateExtraParams();
55
56 if (colspan != null) {
57 addParameter("colspan", findValue(colspan, Integer.class));
58 }
59
60 if (groupColumns != null) {
61 addParameter("groupColumns", findValue(groupColumns, Integer.class));
62 }
63
64 if (labelCssClass != null) {
65 addParameter("labelCssClass", findString(labelCssClass));
66 }
67
68 if (labelCssStyle != null) {
69 addParameter("labelCssStyle", findString(labelCssStyle));
70 }
71
72 if (helpText != null) {
73 addParameter("helpText", findString(helpText));
74 }
75
76 if (inputPrepend != null) {
77 addParameter("inputPrepend", findString(inputPrepend));
78 }
79
80 if (inputAppend != null) {
81 addParameter("inputAppend", findString(inputAppend));
82 }
83
84 if (!parameters.containsKey("value")) {
85 Object nameValue = findValue(name);
86 if (nameValue instanceof Date) {
87 addParameter("dateValue", (Object) nameValue);
88 } else if (nameValue instanceof Calendar) {
89 addParameter("dateValue", ((Calendar) nameValue).getTime());
90 }
91 }
92
93 GboatViewUtil.addReadonlyParameter(this, request);
94 }
95
96 @StrutsTagAttribute(description="控件所占的列数,只在水平布局的表单中才生效", type="Integer")
97 public void setColspan(String colspan) {
98 this.colspan = colspan;
99 }
100
101 @StrutsTagAttribute(description="控件所占栅栏布局的列数,如果设置了该值,则会为控件最外层的 DIV 加上 col-sm-* 的样式类", type="Integer")
102 public void setGroupColumns(String groupColumns) {
103 this.groupColumns = groupColumns;
104 }
105
106 @StrutsTagAttribute(description="标签的 CSS 样式类")
107 public void setLabelCssClass(String labelCssClass) {
108 this.labelCssClass = labelCssClass;
109 }
110
111 @StrutsTagAttribute(description="标签的 CSS 样式")
112 public void setLabelCssStyle(String labelCssStyle) {
113 this.labelCssStyle = labelCssStyle;
114 }
115
116 @StrutsTagAttribute(description="帮助文本,显示在文本框的下方")
117 public void setHelpText(String helpText) {
118 this.helpText = helpText;
119 }
120
121 @StrutsTagAttribute(description="显示在文本框左侧的内容")
122 public void setInputPrepend(String inputPrepend) {
123 this.inputPrepend = inputPrepend;
124 }
125
126 @StrutsTagAttribute(description="显示在文本框右侧的内容")
127 public void setInputAppend(String inputAppend) {
128 this.inputAppend = inputAppend;
129 }
130
131 }