1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib.cewolf;
25
26 import java.util.HashMap;
27
28 import javax.servlet.jsp.JspException;
29
30 import de.laures.cewolf.taglib.DataAware;
31 import de.laures.cewolf.DatasetProducer;
32
33 import org.jfree.data.general.DefaultPieDataset;
34
35 import org.dbforms.taglib.AbstractDbBaseHandlerTag;
36 import org.dbforms.config.ResultSetVector;
37
38 /***
39 *
40 * This tag defines PieData for cewolf
41 *
42 * @author Henner Kollmann
43 *
44 */
45
46 public class CewolfPieDataTag extends AbstractDbBaseHandlerTag {
47 private String categoryField;
48
49 private String dataField;
50
51 public int doEndTag() throws JspException {
52 DefaultPieDataset ds = new DefaultPieDataset();
53 ResultSetVector rsv = getParentForm().getResultSetVector();
54 for (int i = 0; i < rsv.size(); i++) {
55 Comparable c = (Comparable) rsv.getFieldAsObject(i,
56 getCategoryField());
57 Number n = (Number) rsv.getFieldAsObject(i, getDataField());
58 ds.setValue(c, n);
59 }
60 DatasetProducer dataProducer = new DbFormsDatasetProducer(ds);
61 DataAware dw = (DataAware) findAncestorWithClass(this, DataAware.class);
62 dw.setDataProductionConfig(dataProducer, new HashMap(), false);
63 return SKIP_BODY;
64 }
65
66 /***
67 * @return Returns the categoryField.
68 */
69 public String getCategoryField() {
70 return categoryField;
71 }
72
73 /***
74 * @param categoryField
75 * The categoryField to set.
76 */
77 public void setCategoryField(String categoryField) {
78 this.categoryField = categoryField;
79 }
80
81 /***
82 * @return Returns the dataField.
83 */
84 public String getDataField() {
85 return dataField;
86 }
87
88 /***
89 * @param dataField
90 * The dataField to set.
91 */
92 public void setDataField(String dataField) {
93 this.dataField = dataField;
94 }
95
96 public void doFinally() {
97 super.doFinally();
98 categoryField = null;
99 dataField = null;
100 }
101
102 }