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.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.Map ; 30 31 70 public class SortTag extends BaseHandlerTag { 71 72 protected transient final Log log = LogFactory.getLog(SortTag.class); 73 74 77 protected String fieldName; 78 79 83 protected String property; 84 85 88 protected String rowIterators = null; 89 90 91 100 public String getFieldName() { 101 return fieldName; 102 } 103 104 109 public void setFieldName(String fieldName) { 110 this.fieldName = fieldName; 111 } 112 113 122 public String getProperty() { 123 return property; 124 } 125 126 131 public void setProperty(String property) { 132 this.property = property; 133 } 134 135 145 public String getRowIterators() { 146 return rowIterators; 147 } 148 149 155 public void setRowIterators(String rowIterators) { 156 this.rowIterators = rowIterators; 157 } 158 159 165 public void doTag() throws JspException , IOException { 166 167 PageContext pageContext = (PageContext ) getJspContext(); 168 169 GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class); 170 171 if ( parentGridTag == null ) { 172 JspTagException e = new JspTagException ("Parent tag is invalid! This tag is only valid when nested within 'grid' tag"); 173 throw e; 174 } 175 176 ColumnTag parentColumnTag = (ColumnTag) findAncestorWithClass(this, ColumnTag.class); 178 if ( parentColumnTag != null ) { 179 if ( fieldName == null || fieldName.length() == 0 ) { 180 fieldName = parentColumnTag.getFieldName(); 181 } 182 } 183 184 if ( fieldName == null || "".equals(fieldName) ) { 185 String errorMessage = "There is no ancestor 'column' tag and no fieldName attribute is specified!"; 187 if ( log.isErrorEnabled() ) { 188 log.error(errorMessage); 189 } 190 JspTagException e = new JspTagException (errorMessage); 191 throw e; 192 } 193 194 String pageUrl = parentGridTag.getPageUrl(); 195 Map parameterMap = parentGridTag.getParameterMap(); 196 parameterMap.put("sortField", fieldName); 197 if ( property != null ) { 198 parameterMap.put("property", property); 199 } 200 parameterMap.put("gridName", parentGridTag.getName()); 201 parameterMap.put("pageNumber", parentGridTag.getCurrentPageNumber()); 202 if ( rowIterators != null ) { 203 parameterMap.put("rowIterators", rowIterators); 204 } 205 206 pageUrl += "?" + RequestUtil.createQueryStringFromMap(parameterMap, "&"); 207 208 StringWriter sw = new StringWriter (); 209 StringBuffer sb = sw.getBuffer(); 210 sb.append("<a HREF=\"").append(pageUrl).append("\"").append(prepareAttributes()).append(">"); 211 getJspBody().invoke(sw); 212 sb.append("</a>"); 213 TagUtils.getInstance().write(pageContext, sw.toString()); 214 } 215 216 } 217 | Popular Tags |