1 16 package com.blandware.atleap.webapp.taglib.core.grid; 17 18 import com.blandware.atleap.webapp.util.core.RequestUtil; 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.struts.taglib.TagUtils; 22 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.JspTagException ; 25 import javax.servlet.jsp.PageContext ; 26 import java.io.IOException ; 27 import java.io.StringWriter ; 28 29 30 51 public class StringFilterTag extends BaseFilterTag { 52 53 protected transient final Log log = LogFactory.getLog(StringFilterTag.class); 54 55 61 public void doTag() throws JspException , IOException { 62 63 PageContext pageContext = (PageContext ) getJspContext(); 64 65 GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class); 66 67 if ( parentGridTag == null ) { 68 JspTagException e = new JspTagException ("Parent tag is invalid! This tag is only valid when nested within 'grid' tag"); 69 throw e; 70 } 71 72 ColumnTag parentColumnTag = (ColumnTag) findAncestorWithClass(this, ColumnTag.class); 74 if ( parentColumnTag != null ) { 75 if ( fieldName == null || fieldName.length() == 0 ) { 76 fieldName = parentColumnTag.getFieldName(); 77 } 78 79 if ( fieldKey == null || fieldKey.length() == 0 ) { 80 fieldKey = parentColumnTag.getFieldKey(); 81 } 82 } 83 84 if ( fieldName == null || "".equals(fieldName) ) { 85 String errorMessage = "There is no ancestor 'column' tag and no fieldName attribute is specified!"; 87 if ( log.isErrorEnabled() ) { 88 log.error(errorMessage); 89 } 90 JspTagException e = new JspTagException (errorMessage); 91 throw e; 92 } 93 94 95 String pageUrl = RequestUtil.getPageUrl(parentGridTag); 96 97 String scriptCall = "showStringFilterWindow(\'" + fieldName + "\', \'" + parentGridTag.getName() + 98 "\', \'" + pageUrl + "\'"; 99 100 if ( fieldKey == null ) { 101 fieldKey = ""; 102 } 103 scriptCall += ", \'" + fieldKey + "\'"; 104 105 if ( rowIterators == null ) { 106 rowIterators = ""; 107 } 108 scriptCall += ", \'" + rowIterators + "\'"; 109 110 scriptCall += ");"; 111 112 if ( onclick != null && onclick.length() != 0 ) { 113 int k = onclick.indexOf("return false"); 114 if ( k != -1 ) { 115 onclick = onclick.substring(0, k); 116 } 117 } else { 118 onclick = new String (); 119 } 120 onclick += scriptCall + " return false;"; 121 StringWriter sw = new StringWriter (); 122 StringBuffer sb = sw.getBuffer(); 123 sb.append("<a HREF=\"javascript:void(0)\"").append(prepareAttributes()).append(">"); 124 getJspBody().invoke(sw); 125 sb.append("</a>"); 126 TagUtils.getInstance().write(pageContext, sw.toString()); 127 } 128 129 } 130 | Popular Tags |