1 16 package org.ajaxtags.tags; 17 18 import java.io.IOException ; 19 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.JspWriter ; 22 import javax.servlet.jsp.tagext.TagSupport ; 23 24 import org.apache.commons.lang.StringUtils; 25 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 26 27 33 public class AjaxAutocompleteTag extends TagSupport { 34 35 38 private static final long serialVersionUID = -6332721548834673822L; 39 40 private String var; 41 42 private String attachTo; 43 44 private String baseUrl; 45 46 private String source; 47 48 private String target; 49 50 private String parameters; 51 52 private String minimumCharacters; 53 54 private String appendSeparator; 55 56 private String className; 57 58 private String preFunction; 59 60 private String postFunction; 61 62 private String errorFunction; 63 64 private String parser; 65 66 private String indicator; 67 68 public String getAppendSeparator() { 69 return appendSeparator; 70 } 71 72 public void setAppendSeparator(String appendSeparator) { 73 this.appendSeparator = appendSeparator; 74 } 75 76 public String getBaseUrl() { 77 return baseUrl; 78 } 79 80 public void setBaseUrl(String baseUrl) { 81 this.baseUrl = baseUrl; 82 } 83 84 public String getClassName() { 85 return className; 86 } 87 88 public void setClassName(String className) { 89 this.className = className; 90 } 91 92 public String getErrorFunction() { 93 return errorFunction; 94 } 95 96 public void setErrorFunction(String errorFunction) { 97 this.errorFunction = errorFunction; 98 } 99 100 public String getIndicator() { 101 return indicator; 102 } 103 104 public void setIndicator(String indicator) { 105 this.indicator = indicator; 106 } 107 108 public String getMinimumCharacters() { 109 return minimumCharacters; 110 } 111 112 public void setMinimumCharacters(String minimumCharacters) { 113 this.minimumCharacters = minimumCharacters; 114 } 115 116 public String getVar() { 117 return var; 118 } 119 120 public void setVar(String var) { 121 this.var = var; 122 } 123 124 public String getAttachTo() { 125 return attachTo; 126 } 127 128 public void setAttachTo(String attachTo) { 129 this.attachTo = attachTo; 130 } 131 132 public String getParameters() { 133 return parameters; 134 } 135 136 public void setParameters(String parameters) { 137 this.parameters = parameters; 138 } 139 140 public String getParser() { 141 return parser; 142 } 143 144 public void setParser(String parser) { 145 this.parser = parser; 146 } 147 148 public String getPreFunction() { 149 return preFunction; 150 } 151 152 public void setPreFunction(String preFunction) { 153 this.preFunction = preFunction; 154 } 155 156 public String getPostFunction() { 157 return postFunction; 158 } 159 160 public void setPostFunction(String postFunction) { 161 this.postFunction = postFunction; 162 } 163 164 public String getSource() { 165 return source; 166 } 167 168 public void setSource(String source) { 169 this.source = source; 170 } 171 172 public String getTarget() { 173 return target; 174 } 175 176 public void setTarget(String target) { 177 this.target = target; 178 } 179 180 @Override 181 public int doStartTag() throws JspException { 182 this.baseUrl = (String ) ExpressionEvaluatorManager.evaluate("baseUrl", this.baseUrl, 184 String .class, this, super.pageContext); 185 this.source = (String ) ExpressionEvaluatorManager.evaluate("source", this.source, String .class, 186 this, super.pageContext); 187 this.target = (String ) ExpressionEvaluatorManager.evaluate("target", this.target, String .class, 188 this, super.pageContext); 189 this.className = (String ) ExpressionEvaluatorManager.evaluate("className", this.className, 190 String .class, this, super.pageContext); 191 192 if (this.var != null) { 194 this.var = (String ) ExpressionEvaluatorManager.evaluate("var", this.var, String .class, this, 195 super.pageContext); 196 } 197 if (this.attachTo != null) { 198 this.attachTo = (String ) ExpressionEvaluatorManager.evaluate("attachTo", this.attachTo, 199 String .class, this, super.pageContext); 200 } 201 if (this.parameters != null) { 202 this.parameters = (String ) ExpressionEvaluatorManager.evaluate("parameters", this.parameters, 203 String .class, this, super.pageContext); 204 } 205 if (this.minimumCharacters != null) { 206 this.minimumCharacters = (String ) ExpressionEvaluatorManager.evaluate("minimumCharacters", 207 this.minimumCharacters, String .class, this, super.pageContext); 208 } 209 if (this.indicator != null) { 210 this.indicator = (String ) ExpressionEvaluatorManager.evaluate("indicator", 211 this.indicator, String .class, this, super.pageContext); 212 } 213 if (this.preFunction != null) { 214 this.preFunction = (String ) ExpressionEvaluatorManager.evaluate("preFunction", 215 this.preFunction, String .class, this, super.pageContext); 216 } 217 if (this.postFunction != null) { 218 this.postFunction = (String ) ExpressionEvaluatorManager.evaluate("postFunction", 219 this.postFunction, String .class, this, super.pageContext); 220 } 221 if (this.errorFunction != null) { 222 this.errorFunction = (String ) ExpressionEvaluatorManager.evaluate("errorFunction", 223 this.errorFunction, String .class, this, super.pageContext); 224 } 225 return SKIP_BODY; 226 } 227 228 @Override 229 public int doEndTag() throws JspException { 230 OptionsBuilder options = new OptionsBuilder(); 231 options.add("source", this.source, true).add("target", this.target, true).add("className", 232 this.className, true); 233 if (this.parameters != null) 234 options.add("parameters", this.parameters, true); 235 if (this.indicator != null) 236 options.add("indicator", this.indicator, true); 237 if (this.minimumCharacters != null) 238 options.add("minimumCharacters", this.minimumCharacters, true); 239 if (this.appendSeparator != null) 240 options.add("appendSeparator", this.appendSeparator, true); 241 if (this.preFunction != null) 242 options.add("preFunction", this.preFunction, false); 243 if (this.postFunction != null) 244 options.add("postFunction", this.postFunction, false); 245 if (this.errorFunction != null) 246 options.add("errorFunction", this.errorFunction, false); 247 if (this.parser != null) 248 options.add("parser", this.parser, false); 249 250 StringBuffer script = new StringBuffer (); 251 script.append("<script type=\"text/javascript\">\n"); 252 if (StringUtils.isNotEmpty(this.var)) { 253 if (StringUtils.isNotEmpty(this.attachTo)) { 254 script.append(this.attachTo).append(".").append(this.var); 255 } else { 256 script.append("var ").append(this.var); 257 } 258 script.append(" = "); 259 } 260 script 261 .append("new AjaxJspTag.Autocomplete(\n") 262 .append("\"") 263 .append(this.baseUrl) 264 .append("\", {\n") 265 .append(options.toString()) 266 .append("});\n") 267 .append("</script>\n\n"); 268 269 JspWriter writer = pageContext.getOut(); 270 try { 271 writer.println(script); 272 } catch (IOException e) { 273 throw new JspException (e.getMessage()); 274 } 275 return EVAL_PAGE; 276 } 277 278 @Override 279 public void release() { 280 this.var = null; 281 this.attachTo = null; 282 this.baseUrl = null; 283 this.className = null; 284 this.preFunction = null; 285 this.errorFunction = null; 286 this.minimumCharacters = null; 287 this.appendSeparator = null; 288 this.parameters = null; 289 this.postFunction = null; 290 this.source = null; 291 this.target = null; 292 this.parser = null; 293 this.indicator = null; 294 super.release(); 295 } 296 297 } 298
| Popular Tags
|