1 package gboat2.base.view.components;
2
3 import java.io.Writer;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import org.apache.commons.lang3.RandomStringUtils;
9 import org.apache.commons.lang3.StringUtils;
10 import org.apache.struts2.components.ClosingUIBean;
11 import org.apache.struts2.views.annotations.StrutsTag;
12 import org.apache.struts2.views.annotations.StrutsTagAttribute;
13 import org.springframework.util.Assert;
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 @StrutsTag(
40 name = "tab",
41 tldTagClass = "gboat2.base.view.jsp.TabTag",
42 description = "创建 jquery-ui tab 控件",
43 allowDynamicAttributes = true)
44 public class Tab extends ClosingUIBean {
45
46 public static final String TEMPLATE = "tab";
47 public static final String TEMPLATE_CLOSE = "tab-close";
48
49 protected String closable;
50 protected String formIds;
51 protected String href;
52
53 public Tab(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
54 super(stack, request, response);
55 }
56
57 @Override
58 public String getDefaultOpenTemplate() {
59 return TEMPLATE;
60 }
61
62 @Override
63 public String getDefaultTemplate() {
64 return TEMPLATE_CLOSE;
65 }
66
67 @Override
68 public void evaluateExtraParams() {
69 super.evaluateExtraParams();
70
71 TabbedPanel tabbedPanel = (TabbedPanel) findAncestor(TabbedPanel.class);
72 Assert.notNull(tabbedPanel, "<g2:tab> 标签必须位于 <g2:tabbedpanel> 标签中!");
73 addParameter("tabbedPanelId", tabbedPanel.getId());
74
75 if (closable != null)
76 addParameter("closable", findValue(closable, Boolean.class));
77
78 if (formIds != null)
79 addParameter("formIds", findString(formIds));
80
81 if (href != null)
82 addParameter("href", findString(href));
83
84 if (StringUtils.isBlank(id)) {
85 this.id = "tab_" + RandomStringUtils.randomNumeric(3);
86 addParameter("id", this.id);
87 }
88 }
89
90 @Override
91 public boolean end(Writer writer, String body) {
92 return super.end(writer, StringUtils.defaultIfBlank(body, label));
93 }
94
95 @StrutsTagAttribute(description = "是否可以关闭", type = "Boolean", defaultValue = "false")
96 public void setClosable(String closable) {
97 this.closable = closable;
98 }
99
100 @StrutsTagAttribute(name = "formIds", description = "在发起 ajax 请求时,会序列化 id 为该值的表单中所有表单域作为请求参数,多个表单 id 之间用逗号分隔")
101 public void setFormIds(String formIds) {
102 this.formIds = formIds;
103 }
104
105 @StrutsTagAttribute(description = "Tab 页显示内容对应的锚链接或 ajax 请求地址,如: #div1 或 /ajax.do", required = true)
106 public void setHref(String href) {
107 this.href = href;
108 }
109 }