1 23 24 package org.dbforms.taglib; 25 26 import org.dbforms.config.*; 27 28 import org.dbforms.util.*; 29 30 import javax.servlet.http.*; 31 import javax.servlet.jsp.*; 32 33 34 35 49 public class DbSearchTag extends DbBaseHandlerTag 50 implements javax.servlet.jsp.tagext.TryCatchFinally { 51 private String defaultValue = null; 52 private String searchAlgo = "sharp"; 53 private String searchMode = "and"; 54 55 60 public void setDefault(String value) { 61 this.defaultValue = value; 62 } 63 64 65 70 public String getDefault() { 71 return defaultValue; 72 } 73 74 75 80 public void setSearchAlgo(String searchAlgo) { 81 this.searchAlgo = searchAlgo; 82 } 83 84 85 90 public String getSearchAlgo() { 91 return searchAlgo; 92 } 93 94 95 100 public void setSearchMode(String searchMode) { 101 this.searchMode = searchMode; 102 } 103 104 105 110 public String getSearchMode() { 111 return searchMode; 112 } 113 114 115 118 public void doCatch(Throwable t) throws Throwable { 119 throw t; 120 } 121 122 123 131 public int doEndTag() throws javax.servlet.jsp.JspException { 132 try { 133 Field field = getField(); 134 135 140 HttpServletRequest request = (HttpServletRequest) pageContext 141 .getRequest(); 142 StringBuffer tagBuf = new StringBuffer (); 143 144 StringBuffer paramNameBuf = new StringBuffer (); 145 paramNameBuf.append(field.getSearchFieldName()); 146 147 String oldValue = ParseUtil.getParameter(request, 148 paramNameBuf.toString()); 149 tagBuf.append("<input type=\"input\" name=\""); 150 tagBuf.append(paramNameBuf.toString()); 151 tagBuf.append("\" "); 152 153 tagBuf.append("value=\""); 154 155 if (oldValue != null) { 156 tagBuf.append(oldValue); 157 } else if (defaultValue != null) { 158 tagBuf.append(defaultValue); 159 } 160 161 tagBuf.append("\""); 162 tagBuf.append(prepareStyles()); 163 tagBuf.append(prepareEventHandlers()); 164 tagBuf.append("/>\n"); 165 166 pageContext.getOut() 167 .write(renderPatternHtmlInputField()); 168 pageContext.getOut() 169 .write(RenderHiddenFields(field)); 170 pageContext.getOut() 171 .write(tagBuf.toString()); 172 } catch (java.io.IOException ioe) { 173 throw new JspException("IO Error: " + ioe.getMessage()); 174 } 175 176 return EVAL_PAGE; 177 } 178 179 182 protected String getFormFieldName() { 183 return getField().getSearchFieldName(); 184 } 185 186 189 public void doFinally() { 190 searchAlgo = "sharp"; 191 searchMode = "and"; 192 defaultValue = null; 193 super.doFinally(); 194 } 195 196 197 204 protected String RenderHiddenFields(Field f) { 205 StringBuffer tagBuf = new StringBuffer (); 206 StringBuffer paramNameBufA = new StringBuffer (); 207 paramNameBufA.append(f.getSearchAlgoName()); 208 tagBuf.append("<input type=\"hidden\" name=\""); 209 tagBuf.append(paramNameBufA.toString()); 210 tagBuf.append("\" value=\""); 211 tagBuf.append(getSearchAlgo()); 212 tagBuf.append("\"/>\n"); 213 214 StringBuffer paramNameBufB = new StringBuffer (); 215 paramNameBufB.append(f.getSearchModeName()); 216 tagBuf.append("<input type=\"hidden\" name=\""); 217 tagBuf.append(paramNameBufB.toString()); 218 tagBuf.append("\" value=\""); 219 tagBuf.append(getSearchMode()); 220 tagBuf.append("\"/>\n"); 221 222 return tagBuf.toString(); 223 } 224 } 225 | Popular Tags |