1 15 package net.mlw.vlh.web.tag; 16 17 import java.lang.reflect.InvocationTargetException ; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.tagext.BodyTagSupport ; 21 22 import net.mlw.vlh.web.tag.support.ParamAddable; 23 import net.mlw.vlh.web.tag.support.Spacer; 24 import net.mlw.vlh.web.util.JspUtils; 25 26 import org.apache.commons.beanutils.PropertyUtils; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 37 public class AddParamTag extends BodyTagSupport 38 { 39 40 private static final long serialVersionUID = 6118198463511925234L; 41 42 45 private static final Log LOGGER = LogFactory.getLog(AddParamTag.class); 46 47 48 private String name = null; 49 50 54 private String property = null; 55 56 60 private String value = null; 61 62 66 private boolean temp = false; 67 68 74 public int doStartTag() throws JspException 75 { 76 ParamAddable parent = (ParamAddable) JspUtils.getParent(this, ParamAddable.class); 77 78 if ((property != null) && (value != null)) 79 { 80 final String message = "For one parameter" + name 81 + "you can not use two values (first dynamic from the property, 2nd static from the value"; 82 LOGGER.error(message); 83 throw new JspException (message); 84 } 85 86 if (name == null) 87 { 88 name = property; 91 } 92 93 if (property != null) 94 { 95 DefaultRowTag rowTag = (DefaultRowTag) JspUtils.getParent(this, DefaultRowTag.class); 96 Object bean = pageContext.getAttribute(rowTag.getBeanName()); 97 if (bean != null && !(bean instanceof Spacer)) 98 { 99 try 100 { 101 value = String.valueOf(PropertyUtils.getProperty(bean, property)); 102 } 103 catch (Exception e) 104 { 105 LOGGER.error("<vlh:addParam> Error getting property '" + property + "'."); 106 value = null; 107 } 108 } 109 else 110 { 111 if (LOGGER.isDebugEnabled()) 112 { 113 LOGGER.debug("Row's JavaBean '" + rowTag.getBeanName() + "' is null or Valuelist is empty!"); 114 } 115 value = null; 116 } 117 } 118 119 if (value == null) 120 { 121 if (LOGGER.isInfoEnabled()) 122 { 123 LOGGER.info("The param '" + addActionParamPrefix(name) + "' is skiped, because it's value is null!"); 124 } 125 } 126 else 127 { 128 129 parent.addParam(addActionParamPrefix(name), value); 130 if (LOGGER.isDebugEnabled()) 131 { 132 LOGGER.debug("The param '" + addActionParamPrefix(name) + "' was added with the value '" + value + "'."); 133 } 134 } 135 136 release(); 137 138 return SKIP_BODY; 139 } 140 141 145 protected String addActionParamPrefix(String param) 146 { 147 if (isTemp()) 148 { 149 return ActionTag.ACTION_TEMP_PARAM_PREFIX + param; 150 } 151 else 152 { 153 return param; 154 } 155 } 156 157 160 public int doAfterBody() throws JspException 161 { 162 bodyContent.clearBody(); 163 return SKIP_BODY; 164 } 165 166 169 public int doEndTag() throws JspException 170 { 171 int result = super.doEndTag(); 172 reset(); 173 return result; 174 } 175 176 179 public String getProperty() 180 { 181 return this.property; 182 } 183 184 188 public void setProperty(String property) 189 { 190 this.property = property; 191 } 192 193 196 public String getName() 197 { 198 return this.name; 199 } 200 201 205 public void setName(String name) 206 { 207 this.name = name; 208 } 209 210 213 public String getValue() 214 { 215 return this.value; 216 } 217 218 221 public void setValue(String value) 222 { 223 this.value = value; 224 } 225 226 229 public boolean isTemp() 230 { 231 return temp; 232 } 233 234 239 public void setTemp(boolean temp) 240 { 241 this.temp = temp; 242 } 243 244 private void reset() 245 { 246 this.name = null; 247 this.property = null; 248 this.temp = false; 249 this.value = null; 250 } 251 252 260 public void release() 261 { 262 super.release(); 263 reset(); 264 } 265 } | Popular Tags |