1
2
3
4
5 package gboat2.base.view.components;
6
7 import gboat2.base.view.GboatViewUtil;
8
9 import java.io.Writer;
10
11 import javax.servlet.http.HttpServletRequest;
12
13 import org.apache.struts2.components.Component;
14 import org.apache.struts2.views.annotations.StrutsTag;
15 import org.apache.struts2.views.annotations.StrutsTagAttribute;
16
17 import com.opensymphony.xwork2.util.ValueStack;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 @StrutsTag(
58 name="block",
59 tldBodyContent="JSP",
60 tldTagClass="gboat2.base.view.jsp.BlockTag",
61 description="定义一个代码块,用于在子页面中进行重写")
62 public class Block extends Component {
63
64 protected HttpServletRequest request;
65
66 protected String id;
67
68 public Block(ValueStack stack, HttpServletRequest request) {
69 super(stack);
70 this.request = request;
71 }
72
73 @Override
74 public boolean start(Writer write) {
75
76 return (getOverriedContent() == null);
77 }
78
79 @Override
80 public boolean end(Writer writer, String body) {
81 Object overriedContent = getOverriedContent();
82 if(overriedContent != null) {
83 body = overriedContent.toString();
84 }
85 return super.end(writer, body );
86 }
87
88 @StrutsTagAttribute(description="代码块的唯一标识")
89 public void setId(String id) {
90 this.id = id;
91 }
92
93
94
95
96
97 protected Object getOverriedContent() {
98 String varName = GboatViewUtil.getOverrideVariableName(id);
99 return this.request.getAttribute(varName);
100 }
101 }