1 /***
2 * Copyright (c) 2003 held jointly by the individual authors.
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; with out even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * > http://www.gnu.org/copyleft/lesser.html
19 * > http://www.opensource.org/licenses/lgpl-license.php
20 */
21 package net.mlw.vlh.web.tag;
22
23 import javax.servlet.jsp.JspException;
24
25 import net.mlw.vlh.web.tag.support.ColumnInfo;
26 import net.mlw.vlh.web.util.JspUtils;
27
28 import org.apache.commons.beanutils.DynaBean;
29 import org.apache.commons.beanutils.DynaClass;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 /***
34 *
35 * @author Matthew L. Wilson
36 * @version $Revision: 1.10 $ $Date: 2005/11/23 15:02:16 $
37 */
38 public class DynaBeanColumnsTag extends DefaultColumnsTag
39 {
40
41 private static final long serialVersionUID = -6875591300948358739L;
42
43 /***
44 * Logger for this class
45 */
46 private static final Log LOGGER = LogFactory.getLog(DynaBeanColumnsTag.class);
47
48 /***
49 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
50 */
51 public int doEndTag() throws JspException
52 {
53 ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class);
54
55 DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class);
56 DynaBean bean = (DynaBean) pageContext.getAttribute(rowTag.getBeanName());
57 if (bean == null)
58 {
59 LOGGER.error("Zero results where returned.");
60 return SKIP_BODY;
61 }
62
63 DynaClass dClass = bean.getDynaClass();
64
65 StringBuffer sb = new StringBuffer();
66 for (int i = 0, length = dClass.getDynaProperties().length; i < length; i++)
67 {
68 String name = dClass.getDynaProperties()[i].getName();
69 if ((include.isEmpty() || include.contains(name)) && (exclude.isEmpty() || !exclude.contains(name)))
70 {
71 if (rowTag.getCurrentRowNumber() == 0)
72 {
73 String displayName = name.substring(0, 1).toUpperCase() + name.substring(1);
74 rowTag.addColumnInfo(new ColumnInfo(displayName, name, defaultSort, null));
75 }
76
77 sb.append(rowTag.getDisplayProvider().getCellPreProcess(null));
78 if (bean.get(name) == null)
79 {
80 sb.append(rootTag.getConfig().getNullToken());
81 }
82 else
83 {
84 sb.append(bean.get(name));
85 }
86
87 sb.append(rowTag.getDisplayProvider().getCellPostProcess());
88 }
89
90 }
91
92 JspUtils.write(pageContext, sb.toString());
93
94 release();
95
96 return EVAL_PAGE;
97 }
98 }