1 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 38 public class DynaBeanColumnsTag extends DefaultColumnsTag 39 { 40 41 private static final long serialVersionUID = -6875591300948358739L; 42 43 46 private static final Log LOGGER = LogFactory.getLog(DynaBeanColumnsTag.class); 47 48 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 } | Popular Tags |