1
2
3
4
5
6
7
8
9
10
11
12 package org.displaytag.tags;
13
14 import java.util.List;
15 import java.util.Map;
16
17 import javax.servlet.jsp.JspException;
18 import javax.servlet.jsp.tagext.BodyTagSupport;
19
20 import org.displaytag.exception.TagStructureException;
21 import org.displaytag.properties.MediaTypeEnum;
22 import org.displaytag.util.MediaUtil;
23
24
25
26
27
28
29
30
31 public class TableFooterTag extends BodyTagSupport implements MediaUtil.SupportsMedia
32 {
33
34
35
36
37 private static final long serialVersionUID = 899149338534L;
38
39
40
41
42 private List supportedMedia;
43
44
45
46
47 private boolean showAsLastRow;
48
49
50
51
52 public int doEndTag() throws JspException
53 {
54 TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);
55
56 if (tableTag == null)
57 {
58 throw new TagStructureException(getClass(), "footer", "table");
59 }
60
61 MediaTypeEnum currentMediaType = (MediaTypeEnum) this.pageContext.findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA);
62 if (currentMediaType != null && !MediaUtil.availableForMedia(this, currentMediaType))
63 {
64 return SKIP_BODY;
65 }
66
67 if (tableTag.isLastIteration())
68 {
69 if (getBodyContent() != null)
70 {
71 tableTag.setFooter(getBodyContent().getString());
72 }
73 }
74
75 return EVAL_PAGE;
76 }
77
78
79
80
81 public int doStartTag() throws JspException
82 {
83 TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);
84
85 if (tableTag == null)
86 {
87 throw new TagStructureException(getClass(), "footer", "table");
88 }
89
90 MediaTypeEnum currentMediaType = (MediaTypeEnum) this.pageContext.findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA);
91 if (!MediaUtil.availableForMedia(this, currentMediaType))
92 {
93 return SKIP_BODY;
94 }
95
96
97 if (tableTag.isLastIteration())
98 {
99 if (tableTag.getVarTotals() != null)
100 {
101 Map totals = tableTag.getTotals();
102 this.pageContext.setAttribute(tableTag.getVarTotals(), totals);
103 }
104
105 return 2;
106 }
107
108 return SKIP_BODY;
109 }
110
111
112
113
114 public void setSupportedMedia(List media)
115 {
116 this.supportedMedia = media;
117 }
118
119
120
121
122 public List getSupportedMedia()
123 {
124 return this.supportedMedia;
125 }
126
127
128
129
130
131 public void setMedia(String media)
132 {
133 MediaUtil.setMedia(this, media);
134 }
135
136
137
138
139 public void release()
140 {
141 this.supportedMedia = null;
142 this.showAsLastRow = false;
143 super.release();
144 }
145
146
147
148
149
150 public void setShowAsLastRow(boolean showAsLastRow)
151 {
152 this.showAsLastRow = showAsLastRow;
153 }
154 }