1 23 24 package org.dbforms.taglib; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import org.dbforms.util.*; 30 31 import java.util.*; 32 33 import javax.servlet.http.*; 34 import javax.servlet.jsp.*; 35 36 37 38 45 public class DbSortTag extends DbBaseHandlerTag 46 implements javax.servlet.jsp.tagext.TryCatchFinally { 47 private static Log logCat = LogFactory.getLog(DbSortTag.class); 49 52 public void doCatch(Throwable t) throws Throwable { 53 throw t; 54 } 55 56 57 65 public int doEndTag() throws javax.servlet.jsp.JspException { 66 try { 67 if (!getField() 68 .hasIsKeySet() && !getField() 69 .hasSortableSet()) { 70 logCat.warn("you should declare " + getField().getName() 71 + " as key or as sortable in your config file, if you use it as ordering field!"); 72 } 73 74 HttpServletRequest request = (HttpServletRequest) pageContext 75 .getRequest(); 76 77 String oldValue = ParseUtil.getParameter(request, 78 getField().getSortFieldName()); 79 80 StringBuffer tagBuf = new StringBuffer (); 81 tagBuf.append("<select name=\""); 82 tagBuf.append(getField().getSortFieldName()); 83 tagBuf.append("\" size=\"0\" onChange=\"javascript:document.dbform.submit()\" >"); 84 85 String strAsc = "Ascending"; 86 String strDesc = "Descending"; 87 String strNone = "None"; 88 89 if (getParentForm() 91 .hasCaptionResourceSet()) { 92 Locale reqLocale = MessageResources.getLocale(request); 93 94 strAsc = MessageResources.getMessage("dbforms.select.sort.ascending", 96 reqLocale, "Ascending"); 97 strDesc = MessageResources.getMessage("dbforms.select.sort.descending", 98 reqLocale, "Descending"); 99 strNone = MessageResources.getMessage("dbforms.select.sort.none", 100 reqLocale, "None"); 101 } 102 103 tagBuf.append("<option value=\"asc\""); 105 106 if ("asc".equalsIgnoreCase(oldValue)) { 107 tagBuf.append(" selected "); 108 } 109 110 tagBuf.append(">") 111 .append(strAsc); 112 113 tagBuf.append("<option value=\"desc\""); 115 116 if ("desc".equalsIgnoreCase(oldValue)) { 117 tagBuf.append(" selected "); 118 } 119 120 tagBuf.append(">") 121 .append(strDesc); 122 123 tagBuf.append("<option value=\"none\" "); 125 126 if ((oldValue == null) || "none".equals(oldValue)) { 127 tagBuf.append(" selected "); 128 } 129 130 tagBuf.append(">") 131 .append(strNone); 132 133 tagBuf.append("</select>"); 134 135 pageContext.getOut() 136 .write(tagBuf.toString()); 137 } catch (java.io.IOException ioe) { 138 throw new JspException("IO Error: " + ioe.getMessage()); 139 } 140 141 return EVAL_PAGE; 142 } 143 144 145 148 public void doFinally() { 149 super.doFinally(); 150 } 151 } 152 | Popular Tags |