1 16 package com.blandware.atleap.webapp.taglib.core.grid; 17 18 import com.blandware.atleap.webapp.taglib.core.grid.util.SetFilter; 19 import com.blandware.atleap.webapp.util.core.RequestUtil; 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.apache.struts.taglib.TagUtils; 23 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.JspTagException ; 26 import javax.servlet.jsp.PageContext ; 27 import java.io.IOException ; 28 import java.io.StringWriter ; 29 import java.util.Collection ; 30 import java.util.Map ; 31 32 33 93 public class SetFilterTag extends BaseFilterTag { 94 95 protected transient final Log log = LogFactory.getLog(SetFilterTag.class); 96 97 100 protected String beanId; 101 102 110 protected String method; 111 112 117 protected Object collection; 118 119 122 protected String label; 123 124 127 protected String value; 128 129 139 public String getBeanId() { 140 return beanId; 141 } 142 143 149 public void setBeanId(String beanId) { 150 this.beanId = beanId; 151 } 152 153 163 public String getMethod() { 164 return method; 165 } 166 167 173 public void setMethod(String method) { 174 this.method = method; 175 } 176 177 187 public Object getCollection() { 188 return collection; 189 } 190 191 197 public void setCollection(Object collection) { 198 this.collection = collection; 199 } 200 201 211 public String getLabel() { 212 return label; 213 } 214 215 221 public void setLabel(String label) { 222 this.label = label; 223 } 224 225 235 public String getValue() { 236 return value; 237 } 238 239 245 public void setValue(String value) { 246 this.value = value; 247 } 248 249 255 public void doTag() throws JspException , IOException { 256 257 PageContext pageContext = (PageContext ) getJspContext(); 258 259 GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class); 260 if ( parentGridTag == null ) { 261 JspTagException e = new JspTagException ("Parent tag is invalid! This tag is only valid when nested within 'grid' tag"); 262 throw e; 263 } 264 265 ColumnTag parentColumnTag = (ColumnTag) findAncestorWithClass(this, ColumnTag.class); 267 if ( parentColumnTag != null ) { 268 if ( fieldName == null || fieldName.length() == 0 ) { 269 fieldName = parentColumnTag.getFieldName(); 270 } 271 272 if ( fieldKey == null || fieldKey.length() == 0 ) { 273 fieldKey = parentColumnTag.getFieldKey(); 274 } 275 } 276 277 if ( fieldName == null || "".equals(fieldName) ) { 278 String errorMessage = "There is no ancestor 'column' tag and no fieldName attribute is specified!"; 280 if ( log.isErrorEnabled() ) { 281 log.error(errorMessage); 282 } 283 JspTagException e = new JspTagException (errorMessage); 284 throw e; 285 } 286 287 if ( (beanId == null || method == null) && collection == null ) { 289 String errorMessage = "Either collection or beanId with method attributes must be specified"; 291 JspTagException e = new JspTagException (errorMessage); 292 throw e; 293 } 294 295 if ( label != null && label.length() > 0 && (value == null || value.length() == 0) ) { 296 String errorMessage = "Either value or label and value properties must be specified, or both omitted"; 298 JspTagException e = new JspTagException (errorMessage); 299 throw e; 300 } 301 302 String pageUrl = RequestUtil.getPageUrl(parentGridTag); 303 304 String scriptCall = "showSetFilterWindow(\'" + fieldName + "\', \'" + parentGridTag.getName() + 305 "\', \'" + pageUrl + "\'"; 306 307 if ( fieldKey == null ) { 308 fieldKey = ""; 309 } 310 311 scriptCall += ", \'" + fieldKey + "\'"; 312 313 if ( beanId == null || method == null ) { 314 beanId = ""; 315 method = ""; 316 if ( !(collection instanceof Map ) && !(collection instanceof Collection ) && !(collection instanceof Object []) ) { 318 String errorMessage = "Only instances of java.util.Collection, java.util.Map and java.lang.Object[] are supported"; 319 JspTagException e = new JspTagException (errorMessage); 320 throw e; 321 } 322 323 pageContext.getSession().setAttribute(SetFilter.AVAILABLE_ELEMENTS, collection); 324 } 325 326 scriptCall += ", \'" + beanId + "\', \'" + method + "\'"; 327 328 if ( label == null ) { 329 label = ""; 330 } 331 332 scriptCall += ", \'" + label + "\'"; 333 334 if ( value == null ) { 335 value = ""; 336 } 337 338 scriptCall += ", \'" + value + "\'"; 339 340 if ( rowIterators == null ) { 341 rowIterators = ""; 342 } 343 344 scriptCall += ", \'" + rowIterators + "\'"; 345 346 scriptCall += ");"; 347 348 if ( onclick != null && onclick.length() != 0 ) { 349 int k = onclick.indexOf("return false"); 350 if ( k != -1 ) { 351 onclick = onclick.substring(0, k); 352 } 353 } else { 354 onclick = new String (); 355 } 356 onclick += scriptCall + " return false;"; 357 StringWriter sw = new StringWriter (); 358 StringBuffer sb = sw.getBuffer(); 359 sb.append("<a HREF=\"javascript:void(0)\"").append(prepareAttributes()).append(">"); 360 getJspBody().invoke(sw); 361 sb.append("</a>"); 362 TagUtils.getInstance().write(pageContext, sw.toString()); 363 } 364 365 } 366 | Popular Tags |