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
10 import com.opensymphony.xwork2.util.ValueStack;
11
12
13
14
15
16
17
18
19
20
21
22
23
24 @StrutsTag(
25 name = "gridPager",
26 tldTagClass = "gboat2.base.view.jsp.GridPagerTag",
27 description = "定义 jqGrid 的分页参数,详见 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:pager")
28 public class GridPager extends UIBean {
29
30 public static final String TEMPLATE = "grid-pager";
31
32 protected String pagerpos;
33 protected String pgbuttons;
34 protected String pginput;
35 protected String pgtext;
36 protected String recordpos;
37 protected String recordtext;
38 protected String rowList;
39 protected String rowNum;
40 protected String viewrecords;
41
42 protected String onPagingTopics;
43
44 public GridPager(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
45 super(stack, request, response);
46 }
47
48 @Override
49 protected String getDefaultTemplate() {
50 return TEMPLATE;
51 }
52
53 @Override
54 public void evaluateExtraParams() {
55 super.evaluateExtraParams();
56
57 if (pagerpos != null)
58 addParameter("pagerpos", findString(pagerpos));
59
60 if (pgbuttons != null)
61 addParameter("pgbuttons", findValue(this.pgbuttons, Boolean.class));
62
63 if (pginput != null)
64 addParameter("pginput", findValue(this.pginput, Boolean.class));
65
66 if (pgtext != null)
67 addParameter("pgtext", findString(pgtext));
68
69 if (recordpos != null)
70 addParameter("recordpos", findString(recordpos));
71
72 if (rowList != null)
73 addParameter("rowList", findString(rowList));
74
75 if (rowNum != null)
76 addParameter("rowNum", findValue(rowNum, Integer.class));
77
78 if (viewrecords != null)
79 addParameter("viewrecords", findValue(this.viewrecords, Boolean.class));
80
81 if (onPagingTopics != null)
82 addParameter("onPagingTopics", findString(onPagingTopics));
83
84 Grid grid = (Grid) findAncestor(Grid.class);
85 if (grid != null) {
86 addParameter("gridId", grid.getId());
87 }
88 }
89
90 @Override
91 @StrutsTagAttribute(description="The template directory.")
92 public void setTemplateDir(String templateDir) {
93 super.setTemplateDir(templateDir);
94 }
95
96 @Override
97 @StrutsTagAttribute(description="The theme (other than default) to use for rendering the element")
98 public void setTheme(String theme) {
99 super.setTheme(theme);
100 }
101
102 @Override
103 @StrutsTagAttribute(description="The template (other than default) to use for rendering the element")
104 public void setTemplate(String template) {
105 super.setTemplate(template);
106 }
107
108 @StrutsTagAttribute(description = "首页、上一页、下一页、尾页等翻页相关的元素的摆放位置,可选值:left, center, right", defaultValue = "center")
109 public void setPagerpos(String pagerpos) {
110 this.pagerpos = pagerpos;
111 }
112
113 @StrutsTagAttribute(description = "是否显示翻页按钮,true|false。只有正确设置了翻页条时,该属性才会生效", type = "Boolean", defaultValue = "true")
114 public void setPgbuttons(String pgbuttons) {
115 this.pgbuttons = pgbuttons;
116 }
117
118 @StrutsTagAttribute(description = "是否显示跳转页面的输入框", type = "Boolean", defaultValue = "true")
119 public void setPginput(String pginput) {
120 this.pginput = pginput;
121 }
122
123 @StrutsTagAttribute(description = "显示页码的文本,定义在国际化文件中,如:共 {0} 页,第 {1} 页", defaultValue = "Page {0} of {1}")
124 public void setPgtext(String pgtext) {
125 this.pgtext = pgtext;
126 }
127
128 @StrutsTagAttribute(description = "记录条数信息(当前显示多少条,共多少条)的摆放位置,可选值:left, center, right", defaultValue = "right")
129 public void setRecordpos(String recordpos) {
130 this.recordpos = recordpos;
131 }
132
133 @StrutsTagAttribute(description = "显示记录条数的文本,定义在国际化文件中,如:{0} - {1} 共 {2} 条", defaultValue = "View {0} - {1} of {2}")
134 public void setRecordtext(String recordtext) {
135 this.recordtext = recordtext;
136 }
137
138 @StrutsTagAttribute(description = "可供选择的每页显示的记录条数,显示在一个下拉框中,多个数值之间使用英文逗号分隔,如: 10,20,30,50,100")
139 public void setRowList(String rowList) {
140 this.rowList = rowList;
141 }
142
143 @StrutsTagAttribute(description = "每页显示的记录条数,这个参数是要被传递到后台的", type="Integer", defaultValue="20")
144 public void setRowNum(String rowNum) {
145 this.rowNum = rowNum;
146 }
147
148 @StrutsTagAttribute(description = "是否显示总记录数相关的信息,即 recordtext 设置的值", defaultValue = "true", type = "Boolean")
149 public void setViewrecords(String viewrecords) {
150 this.viewrecords = viewrecords;
151 }
152
153 @StrutsTagAttribute(description = "触发 onPaging 事件时发布的主题。当点击翻页按钮后或修改了页码文本框中的数值按Enter键后,在请求新数据之前触发该事件。本事件只传递一个参数 pgButton,即点击的按钮对应的字符串,可能的值为 first,last,prev,next,如果事件对应的处理方法返回 stop,则停止加载新数据。")
154 public void setOnPagingTopics(String onPagingTopics) {
155 this.onPagingTopics = onPagingTopics;
156 }
157
158 }