1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.extremecomponents.table.tag;
17
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.apache.commons.beanutils.PropertyUtils;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.extremecomponents.table.bean.Column;
25 import org.extremecomponents.table.model.TableModelUtils;
26
27
28
29 /***
30 * Helper methods for the tag classes. Trying to keep the logic out of the tags so
31 * can move to the JSP2.0 container easier.
32 *
33 * @author $author$
34 */
35 public class TagUtils
36 {
37 private static Log logger = LogFactory.getLog(TableTag.class);
38
39 /***
40 * If no columns are defined then set the columns automatically.
41 * Note: the filtering will not work because the metadata is not set.
42 */
43 public static void autoSetColumns(TableTag tableTag, List rows)
44 throws Exception
45 {
46 logger.info("no columns defined so set them automatically");
47
48
49 for (Iterator iter = rows.iterator(); iter.hasNext();)
50 {
51 Object bean = iter.next();
52 List properties = TableModelUtils.beanProperties(bean);
53 autoAddColumns(tableTag, bean, properties);
54
55 break;
56 }
57
58
59 for (Iterator iter = rows.iterator(); iter.hasNext();)
60 {
61 Object bean = iter.next();
62 List properties = TableModelUtils.beanProperties(bean);
63 tableTag.getModel().getViewHandler().addRow();
64 autoAddColumns(tableTag, bean, properties);
65 }
66 }
67
68 public static void autoAddColumns(TableTag tableTag, Object bean, List properties)
69 throws Exception
70 {
71 for (Iterator iter = properties.iterator(); iter.hasNext();)
72 {
73 String property = (String) iter.next();
74
75 if (property.equals("class"))
76 {
77 continue;
78 }
79
80 Object value = PropertyUtils.getProperty(bean, property);
81 Column column = new Column(tableTag.getModel());
82 column.setProperty(property);
83 column.setValue(value);
84
85 if (tableTag.hasMetaData())
86 {
87 tableTag.addColumnValue(property, value);
88 }
89 else
90 {
91 tableTag.addColumnMetaData(column);
92 }
93 }
94 }
95 }