1 21 package net.mlw.vlh.web.tag; 22 23 import java.util.Locale ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.BodyContent ; 28 29 import net.mlw.vlh.web.ValueListConfigBean; 30 import net.mlw.vlh.web.tag.support.ColumnInfo; 31 import net.mlw.vlh.web.util.JspUtils; 32 33 import org.apache.commons.beanutils.PropertyUtils; 34 35 40 public class DefaultColumnCheckBoxTag extends BaseColumnTag 41 { 42 43 private String name; 44 45 private String property; 46 47 50 public int doEndTag() throws JspException 51 { 52 53 ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class); 54 ValueListConfigBean config = rootTag.getConfig(); 55 56 DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class); 57 appendClassCellAttribute(rowTag.getRowStyleClass()); 58 59 Locale locale = config.getLocaleResolver().resolveLocale((HttpServletRequest ) pageContext.getRequest()); 60 61 if (rowTag.getCurrentRowNumber() == 0) 62 { 63 String titleKey = getTitleKey(); 64 String label = (titleKey == null) ? getTitle() : config.getMessageSource().getMessage(titleKey, null, titleKey, locale); 65 66 StringBuffer header = new StringBuffer (512); 67 if (label != null) 68 { 69 header.append(label); 70 } 71 72 header 73 .append("<input type=\"checkbox\" onclick=\"for(i=0; i < this.form.elements.length; i++) {if (this.form.elements[i].name=='") 74 .append(getName()).append("') {this.form.elements[i].checked = this.checked;}}\"/>"); 75 76 ColumnInfo columnInfo = new ColumnInfo(config.getDisplayHelper().help(pageContext, header.toString()), property, null, 77 getAttributes()); 78 79 String toolTipKey = getToolTipKey(); 82 columnInfo.setToolTip((toolTipKey == null) ? getToolTip() : config.getMessageSource().getMessage(toolTipKey, null, toolTipKey, 83 locale)); 84 85 rowTag.addColumnInfo(columnInfo); 86 } 87 88 Object bean = pageContext.getAttribute(rowTag.getBeanName()); 89 Object value = "na"; 90 91 try 92 { 93 value = PropertyUtils.getProperty(bean, property); 94 } 95 catch (Exception e) 96 { 97 } 98 99 StringBuffer sb = new StringBuffer (); 100 101 sb.append(rowTag.getDisplayProvider().getCellPreProcess(getCellAttributes())); 102 103 BodyContent bodyContent = getBodyContent(); 104 if (bodyContent != null && bodyContent.getString() != null && bodyContent.getString().length() > 0) 105 { 106 sb.append(bodyContent.getString()); 107 bodyContent.clearBody(); 108 } 109 else 110 { 111 sb.append("<input type=\"checkbox\" name=\"").append(name).append("\" value=\"").append(value).append("\"/>"); 112 } 113 114 sb.append(rowTag.getDisplayProvider().getCellPostProcess()); 115 JspUtils.write(pageContext, sb.toString()); 116 117 release(); 118 119 return EVAL_PAGE; 120 } 121 122 125 public String getProperty() 126 { 127 return this.property; 128 } 129 130 133 public void setProperty(String property) 134 { 135 this.property = property; 136 } 137 138 141 public String getName() 142 { 143 return this.name; 144 } 145 146 149 public void setName(String name) 150 { 151 this.name = name; 152 } 153 154 private void reset() 155 { 156 this.name = null; 157 this.property = null; 158 } 159 160 168 public void release() 169 { 170 super.release(); 171 reset(); 172 } 173 } | Popular Tags |