1
2
3
4
5 package gboat2.base.view.components;
6
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
10 import org.apache.commons.lang3.RandomStringUtils;
11 import org.apache.commons.lang3.StringUtils;
12 import org.apache.struts2.views.annotations.StrutsTag;
13 import org.apache.struts2.views.annotations.StrutsTagAttribute;
14
15 import com.opensymphony.xwork2.util.ValueStack;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 @StrutsTag(
42 name = "spinner",
43 tldTagClass = "gboat2.base.view.jsp.SpinnerTag",
44 description = "创建一个微调组件(spinner),用于处理各种数字输入。它允许用户直接输入一个值,或通过键盘、鼠标、滚轮微调改变一个已有的值。详见 http://api.jqueryui.com/spinner/",
45 allowDynamicAttributes = true)
46 public class Spinner extends TextField {
47
48 public static final String TEMPLATE = "spinner";
49
50 public static final String JQUERYACTION = "spinner";
51
52 protected String culture;
53 protected String icons;
54 protected String incremental;
55 protected String max;
56 protected String min;
57 protected String numberFormat;
58 protected String page;
59 protected String step;
60 protected String mouseWheel;
61
62 protected String onChangeTopics;
63 protected String onSpinTopics;
64 protected String onStartTopics;
65 protected String onStopTopics;
66
67 public Spinner(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
68 super(stack, request, response);
69 }
70
71 @Override
72 protected String getDefaultTemplate() {
73 return TEMPLATE;
74 }
75
76 @Override
77 public void evaluateExtraParams() {
78 super.evaluateExtraParams();
79
80 addParameter("jqueryaction", JQUERYACTION);
81
82 if (culture != null)
83 addParameter("culture", findString(culture));
84
85 if (icons != null)
86 addParameter("icons", findString(incremental));
87
88 if (incremental != null)
89 addParameter("incremental", findValue(incremental, Boolean.class));
90
91 if (max != null)
92 addParameter("max", findValue(max, Float.class));
93
94 if (min != null)
95 addParameter("min", findValue(min, Float.class));
96
97 if (numberFormat != null)
98 addParameter("numberFormat", findString(numberFormat));
99
100 if (page != null)
101 addParameter("page", findValue(page, Float.class));
102
103 if (step != null)
104 addParameter("step", findValue(step, Float.class));
105
106 if (mouseWheel != null)
107 addParameter("mouseWheel", findValue(mouseWheel, Boolean.class));
108
109 if (onChangeTopics != null)
110 addParameter("onChangeTopics", findString(onChangeTopics));
111
112 if (onSpinTopics != null)
113 addParameter("onSpinTopics", findString(onSpinTopics));
114
115 if (onStartTopics != null)
116 addParameter("onStartTopics", findString(onStartTopics));
117
118 if (onStopTopics != null)
119 addParameter("onStopTopics", findString(onStopTopics));
120
121 if (StringUtils.isBlank(id)) {
122 this.id = "spinner_" + RandomStringUtils.randomNumeric(3);
123 addParameter("id", this.id);
124 }
125 }
126
127 @StrutsTagAttribute(description = "设置区域,用于用于解析和格式化文本框中的值,主要是用于国际化,如:fr 表示法国,依赖于 Globalize 插件(https://github.com/jquery/globalize)。只在设置了 numberFormat 时该属性才会生效")
128 public void setCulture(String culture) {
129 this.culture = culture;
130 }
131
132 @Override
133 @StrutsTagAttribute(description = "如果设置为 true,则禁用该 spinner(微调组件)。", type = "Boolean", defaultValue = "false")
134 public void setDisabled(String disabled) {
135 super.setDisabled(disabled);
136 }
137
138 @StrutsTagAttribute(description = "微调小按钮图标样式类,如:{down: 'custom-down-icon', up: 'custom-up-icon'}}", defaultValue = "{ down: \"ui-icon-triangle-1-s\", up: \"ui-icon-triangle-1-n\" }")
139 public void setIcons(String icons) {
140 this.icons = icons;
141 }
142
143 @StrutsTagAttribute(description = "如果设置为 true,当按住 spinner(微调组件)按钮不放时,数值会根据 step 的值不断的增加或减少。 当设置为 false 时,所有步骤都是相等的。", type = "Boolean", defaultValue = "true")
144 public void setIncremental(String incremental) {
145 this.incremental = incremental;
146 }
147
148 @StrutsTagAttribute(description = "允许的最大值,如果没有设置则表示没有上限。", type = "Float")
149 public void setMax(String max) {
150 this.max = max;
151 }
152
153 @StrutsTagAttribute(description = "允许的最小值,如果没有设置则表示没有下限。", type = "Float")
154 public void setMin(String min) {
155 this.min = min;
156 }
157
158 @StrutsTagAttribute(description = "格式化数值的方式,依赖于 Globalize 插件(https://github.com/jquery/globalize)。最常用的值为: n - 表示 10 进制数值, C - 表示货币值")
159 public void setNumberFormat(String numberFormat) {
160 this.numberFormat = numberFormat;
161 }
162
163 @StrutsTagAttribute(description = "使用 pageUp()/pageDown() 的方法或按 PageUp 和 PageDown 键进行分页时,增加或减少的数值。", type = "Float", defaultValue = "10")
164 public void setPage(String page) {
165 this.page = page;
166 }
167
168 @StrutsTagAttribute(description = "使用 stepUp()/stepDown()方法或按 UP 和 DOWN 键进行微调时,增加或减少的数值。", type = "Float", defaultValue = "1")
169 public void setStep(String step) {
170 this.step = step;
171 }
172
173 @StrutsTagAttribute(description = "如果设为 true,则在鼠标悬停在微调小按钮上时就调整数值", type = "Boolean", defaultValue = "false")
174 public void setMouseWheel(String mouseWheel) {
175 this.mouseWheel = mouseWheel;
176 }
177
178 @StrutsTagAttribute(description = "当spinner微调器的值改变并且输入元素(input)失去焦点时,即触发 change 事件时,发布的消息主题,多值之间使用逗号分隔")
179 public void setOnChangeTopics(String onChangeTopics) {
180 this.onChangeTopics = onChangeTopics;
181 }
182
183 @StrutsTagAttribute(description = "在递增/递减的时,即触发 spin 事件时,发布的消息主题,多值之间使用逗号分隔")
184 public void setOnSpinTopics(String onSpinTopics) {
185 this.onSpinTopics = onSpinTopics;
186 }
187
188 @StrutsTagAttribute(description = "微调开始之前,即触发 start 事件时,发布的消息主题,多值之间使用逗号分隔")
189 public void setOnStartTopics(String onStartTopics) {
190 this.onStartTopics = onStartTopics;
191 }
192
193 @StrutsTagAttribute(description = "微调结束后,即触发 stop 事件时,发布的消息主题,多值之间使用逗号分隔")
194 public void setOnStopTopics(String onStopTopics) {
195 this.onStopTopics = onStopTopics;
196 }
197 }