1 package gboat2.base.view.components;
2
3 import javax.servlet.http.HttpServletRequest;
4 import javax.servlet.http.HttpServletResponse;
5
6 import org.apache.struts2.components.UIBean;
7 import org.apache.struts2.views.annotations.StrutsTag;
8 import org.apache.struts2.views.annotations.StrutsTagAttribute;
9 import org.springframework.util.Assert;
10
11 import com.opensymphony.xwork2.util.ValueStack;
12
13
14
15
16
17
18
19
20 @StrutsTag(
21 name = "gridColumn",
22 tldTagClass = "gboat2.base.view.jsp.GridColumnTag",
23 description = "创建表格的列,详见 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options")
24 public class GridColumn extends UIBean {
25
26 public static final String TEMPLATE = "grid-column";
27
28 protected String align;
29 protected String datefmt;
30 protected String defval;
31 protected String displayTitle;
32 protected String editable;
33 protected String editoptions;
34 protected String editrules;
35 protected String edittype;
36 protected String firstsortorder;
37 protected String fixed;
38 protected String formoptions;
39 protected String formatoptions;
40 protected String formatter;
41 protected String frozen;
42 protected String hidedlg;
43 protected String hidden;
44 protected String index;
45 protected String jsonmap;
46 protected String key;
47 protected String resizable;
48 protected String search;
49 protected String searchtype;
50 protected String searchoptions;
51 protected String surl;
52 protected String sortable;
53 protected String sorttype;
54 protected String unformat;
55 protected String viewable;
56 protected String width;
57
58 public GridColumn(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
59 super(stack, request, response);
60 }
61
62 @Override
63 protected String getDefaultTemplate() {
64 return TEMPLATE;
65 }
66
67 @Override
68 public void evaluateExtraParams() {
69 super.evaluateExtraParams();
70
71 if (align != null)
72 addParameter("align", findString(align));
73
74 if (datefmt != null)
75 addParameter("datefmt", findString(datefmt));
76
77 if (defval != null)
78 addParameter("defval", findString(defval));
79
80 if (displayTitle != null)
81 addParameter("displayTitle", findValue(this.displayTitle, Boolean.class));
82
83 if (editable != null)
84 addParameter("editable", findValue(this.editable, Boolean.class));
85
86 if (editoptions != null)
87 addParameter("editoptions", findString(editoptions));
88
89 if (editrules != null)
90 addParameter("editrules", findString(editrules));
91
92 if (edittype != null)
93 addParameter("edittype", findString(edittype));
94
95 if (firstsortorder != null)
96 addParameter("firstsortorder", findString(firstsortorder));
97
98 if (fixed != null)
99 addParameter("fixed", findValue(this.fixed, Boolean.class));
100
101 if (formoptions != null)
102 addParameter("formoptions", findString(formoptions));
103
104 if (formatoptions != null)
105 addParameter("formatoptions", findString(formatoptions));
106
107 if (formatter != null)
108 addParameter("formatter", findString(formatter));
109
110 if (frozen != null)
111 addParameter("frozen", findValue(this.frozen, Boolean.class));
112
113 if (hidedlg != null)
114 addParameter("hidedlg", findValue(this.hidedlg, Boolean.class));
115
116 if (hidden != null)
117 addParameter("hidden", findValue(this.hidden, Boolean.class));
118
119 if (index != null)
120 addParameter("index", findString(index));
121
122 if (jsonmap != null)
123 addParameter("jsonmap", findString(jsonmap));
124
125 if (key != null)
126 addParameter("key", findValue(this.key, Boolean.class));
127
128 if (resizable != null)
129 addParameter("resizable", findValue(this.resizable, Boolean.class));
130
131 if (search != null)
132 addParameter("search", findValue(this.search, Boolean.class));
133
134 if (searchtype != null)
135 addParameter("searchtype", findString(searchtype));
136
137 if (searchoptions != null)
138 addParameter("searchoptions", findString(searchoptions));
139
140 if (surl != null)
141 addParameter("surl", findString(surl));
142
143 if (sortable != null)
144 addParameter("sortable", findValue(this.sortable, Boolean.class));
145
146 if (sorttype != null)
147 addParameter("sorttype", findString(sorttype));
148
149 if (unformat != null)
150 addParameter("unformat", findString(unformat));
151
152 if (viewable != null)
153 addParameter("viewable", findValue(viewable, Boolean.class));
154
155 if (width != null)
156 addParameter("width", findString(width));
157
158 Grid grid = (Grid) findAncestor(Grid.class);
159 Assert.notNull(grid, "<g2:gridColumn> 必须嵌套在 <g2:grid> 标签中!");
160 addParameter("gridId", grid.getId());
161 }
162
163 @Override
164 @StrutsTagAttribute(description="The template directory.")
165 public void setTemplateDir(String templateDir) {
166 super.setTemplateDir(templateDir);
167 }
168
169 @Override
170 @StrutsTagAttribute(description="The theme (other than default) to use for rendering the element")
171 public void setTheme(String theme) {
172 super.setTheme(theme);
173 }
174
175 @Override
176 @StrutsTagAttribute(description="The template (other than default) to use for rendering the element")
177 public void setTemplate(String template) {
178 super.setTemplate(template);
179 }
180
181 @Override
182 @StrutsTagAttribute(description = "CSS 样式类, 如: ui-ellipsis")
183 public void setCssClass(String cssClass) {
184 super.setCssClass(cssClass);
185 }
186
187 @Override
188 @StrutsTagAttribute(description = "When colNames array is empty, defines the heading for this column. If both the colNames array and this setting are empty, the heading for this column comes from the name property")
189 public void setLabel(String label) {
190 super.setLabel(label);
191 }
192
193 @Override
194 @StrutsTagAttribute(description = "列头显示的文字")
195 public void setTitle(String title) {
196 super.setTitle(title);
197 }
198
199 @Override
200 @StrutsTagAttribute(description = "表格列的名称,所有关键字,保留字都不能作为名称使用包括subgrid, cb and rn", required = true)
201 public void setName(String name) {
202 super.setName(name);
203 }
204
205 @StrutsTagAttribute(description = "内容对齐方式,可选值:left, center, right", defaultValue="left")
206 public void setAlign(String align) {
207 this.align = align;
208 }
209
210 @StrutsTagAttribute(description = "日期格式,当 sorttype=date 或 editrules={date:true} 时会用使用到,如:Y-m-d")
211 public void setDatefmt(String datefmt) {
212 this.datefmt = datefmt;
213 }
214
215 @StrutsTagAttribute(description = "该列作为查询条件时显示的默认值")
216 public void setDefval(String defval) {
217 this.defval = defval;
218 }
219
220 @StrutsTagAttribute(description = "鼠标移到单元格上时,是否显示 title 属性的值", type = "Boolean", defaultValue = "true")
221 public void setDisplayTitle(String displayTitle) {
222 this.displayTitle = displayTitle;
223 }
224
225 @StrutsTagAttribute(description = "是否可编辑", type = "Boolean", defaultValue = "false")
226 public void setEditable(String editable) {
227 this.editable = editable;
228 }
229
230 @StrutsTagAttribute(description = "编辑的一系列选项,如:{dataUrl: '${ctx}/admin/deplistforstu.action'}")
231 public void setEditoptions(String editoptions) {
232 this.editoptions = editoptions;
233 }
234
235 @StrutsTagAttribute(description = "编辑的规则,如:{number:true, required: true, minValue:10, maxValue:100}")
236 public void setEditrules(String editrules) {
237 this.editrules = editrules;
238 }
239
240 @StrutsTagAttribute(description = "编辑的类型。可选值:text, textarea, select, checkbox, password, button, image 和 file.", defaultValue="text")
241 public void setEdittype(String edittype) {
242 this.edittype = edittype;
243 }
244
245 @StrutsTagAttribute(description = "If set to asc or desc, the column will be sorted in that direction on first sort.Subsequent sorts of the column will toggle as usual")
246 public void setFirstsortorder(String firstsortorder) {
247 this.firstsortorder = firstsortorder;
248 }
249
250 @StrutsTagAttribute(description = "当 autowidth=true 时,根据父容器自动调整列宽时,列宽度是否固定不可变,true|false", type = "Boolean", defaultValue = "false")
251 public void setFixed(String fixed) {
252 this.fixed = fixed;
253 }
254
255 @StrutsTagAttribute(description = "对于form 进行编辑时的属性设置,如: { label:'My Label', elmprefix:'(*)', rowpos:1, colpos:2 }")
256 public void setFormoptions(String formoptions) {
257 this.formoptions = formoptions;
258 }
259
260 @StrutsTagAttribute(description = "对某些列进行格式化的设置")
261 public void setFormatoptions(String formatoptions) {
262 this.formatoptions = formatoptions;
263 }
264
265 @StrutsTagAttribute(description = "对列进行格式化时设置的函数名或者数据的格式类型(integer、number、currency、date、email、link、showlink、checkbox、select),详见 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter")
266 public void setFormatter(String formatter) {
267 this.formatter = formatter;
268 }
269
270 @StrutsTagAttribute(description = "是否冻结该列", type = "Boolean", defaultValue = "false")
271 public void setFrozen(String frozen) {
272 this.frozen = frozen;
273 }
274
275 @StrutsTagAttribute(description = "在查看详细的对话框中是否隐藏此列", type = "Boolean", defaultValue = "false")
276 public void setHidedlg(String hidedlg) {
277 this.hidedlg = hidedlg;
278 }
279
280 @StrutsTagAttribute(description = "在初始化表格时是否要隐藏此列", type = "Boolean", defaultValue = "false")
281 public void setHidden(String hidden) {
282 this.hidden = hidden;
283 }
284
285 @StrutsTagAttribute(description = "索引。其和后台交互的参数为 sidx,一般对应 PO 的属性名")
286 public void setIndex(String index) {
287 this.index = index;
288 }
289
290 @StrutsTagAttribute(description = "定义了返回的json数据映射")
291 public void setJsonmap(String jsonmap) {
292 this.jsonmap = jsonmap;
293 }
294
295 @StrutsTagAttribute(description = "当从服务器端返回的数据中没有 id 时,将此作为唯一 rowid(即进行编辑和删除操作时传入的主键) 使用。只有一个列可以做这项设置,如果设置多个,那么只选取第一个,其他被忽略", type = "Boolean", defaultValue = "false")
296 public void setKey(String key) {
297 this.key = key;
298 }
299
300 @StrutsTagAttribute(description = "是否可以通过拖指调整列宽", type = "Boolean", defaultValue = "true")
301 public void setResizable(String resizable) {
302 this.resizable = resizable;
303 }
304
305 @StrutsTagAttribute(description = "在搜索模式下,定义此列是否可以作为搜索列", type = "Boolean", defaultValue = "true")
306 public void setSearch(String search) {
307 this.search = search;
308 }
309
310 @StrutsTagAttribute(description = "字段对应搜索元素的类型,可选值:text - 文本框;select - 下拉框")
311 public void setSearchtype(String searchtype) {
312 this.searchtype = searchtype;
313 }
314
315 @StrutsTagAttribute(description = "设置搜索参数,如:{sopt:['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']}")
316 public void setSearchoptions(String searchoptions) {
317 this.searchoptions = searchoptions;
318 }
319
320 @StrutsTagAttribute(description = "edittype 为 'select' 时,通过该 URL 加载下拉框中的选项值")
321 public void setSurl(String surl) {
322 this.surl = surl;
323 }
324
325 @StrutsTagAttribute(description = "是否可排序", type = "Boolean", defaultValue = "true")
326 public void setSortable(String sortable) {
327 this.sortable = sortable;
328 }
329
330 @StrutsTagAttribute(description = "用在当datatype为local时,定义排序的方式,可选值:int/integer - 对整形数值进行排序, float/number/currency - 对浮点型数值进行排序, date - 对日期进行排序, text - 对文本进行排序, function - 自定义排序方法", defaultValue = "text")
331 public void setSorttype(String sorttype) {
332 this.sorttype = sorttype;
333 }
334
335 @StrutsTagAttribute(description = "对单元格中的值进行反格式化(与 formatter 的操作相反),是一个 js 方法,接受三个参数:cellValue, jqgridOptions, tdElement")
336 public void setUnformat(String unformat) {
337 this.unformat = unformat;
338 }
339
340 @StrutsTagAttribute(description = "调用表格的 viewGridRow() 方法查看记录详情时,是否在查看表单中显示该字段", type = "Boolean", defaultValue = "true")
341 public void setViewable(String viewable) {
342 this.viewable = viewable;
343 }
344
345 @StrutsTagAttribute(description = "列的宽度,单位为像素", type="Integer", defaultValue="150")
346 public void setWidth(String width) {
347 this.width = width;
348 }
349 }