1 16 package com.blandware.atleap.webapp.taglib.core.grid; 17 18 import com.blandware.atleap.webapp.taglib.core.BaseHandlerTag; 19 import com.blandware.atleap.webapp.util.core.RequestUtil; 20 import org.apache.struts.taglib.TagUtils; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.JspTagException ; 24 import javax.servlet.jsp.PageContext ; 25 import java.io.IOException ; 26 import java.io.StringWriter ; 27 import java.util.Map ; 28 29 30 63 public class ClearFilterTag extends BaseHandlerTag { 64 65 67 70 protected String fieldName = null; 71 72 75 protected Boolean all = null; 76 77 78 87 public String getFieldName() { 88 return fieldName; 89 } 90 91 96 public void setFieldName(String fieldName) { 97 this.fieldName = fieldName; 98 } 99 100 109 public Boolean getAll() { 110 return all; 111 } 112 113 118 public void setAll(Boolean all) { 119 this.all = all; 120 } 121 122 128 public void doTag() throws JspException , IOException { 129 130 PageContext pageContext = (PageContext ) getJspContext(); 131 132 GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class); 133 134 if ( parentGridTag == null ) { 135 JspTagException e = new JspTagException ("Parent tag is invalid! This tag is only valid when nested within 'grid' tag"); 136 throw e; 137 } 138 139 if ( fieldName == null && all == null ) { 140 throw new JspTagException ("Either 'fieldName' or 'all' attributes must be specified!"); 141 } 142 143 144 if ( fieldName != null || all.equals(Boolean.TRUE) ) { 145 146 149 String pageUrl = parentGridTag.getPageUrl(); 150 Map parameterMap = RequestUtil.prepareParameterMap(parentGridTag.getParameterMap()); 151 152 parameterMap.put("gridName", parentGridTag.getName()); 153 pageUrl += "?" + RequestUtil.createQueryStringFromMap(parameterMap, "&"); 154 155 if ( fieldName != null ) { 156 parameterMap.put("clearFilter", fieldName); 157 } else { 158 parameterMap.put("clearAllFilters", "true"); 159 } 160 161 StringWriter sw = new StringWriter (); 162 StringBuffer sb = sw.getBuffer(); 163 sb.append("<a HREF=\"").append(pageUrl).append("\"").append(prepareAttributes()).append(">"); 164 getJspBody().invoke(sw); 165 sb.append("</a>"); 166 TagUtils.getInstance().write(pageContext, sw.toString()); 167 } 168 169 } 170 171 } 172 | Popular Tags |