1 17 package org.ajaxtags.tags; 18 19 import java.io.IOException ; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspWriter ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 import org.apache.commons.lang.StringUtils; 26 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 27 28 36 public class AjaxSelectTag extends TagSupport { 37 38 private String var; 39 40 private String attachTo; 41 private String emptyOptionValue; 42 private String emptyOptionName; 43 44 public void setEmptyOptionName(String emptyOptionName) { 45 this.emptyOptionName = emptyOptionName; 46 } 47 48 public String getEmptyOptionName() { 49 return emptyOptionName; 50 } 51 52 public void setEmptyOptionValue(String emptyOptionValue) { 53 this.emptyOptionValue = emptyOptionValue; 54 } 55 56 public String getEmptyOptionValue() { 57 return emptyOptionValue; 58 } 59 60 private boolean doPost; 61 62 public void setDoPost(boolean doPost) { 63 this.doPost = doPost; 64 } 65 66 public boolean getDoPost() { 67 return this.doPost; 68 } 69 70 private String baseUrl; 71 72 private String source; 73 74 private String target; 75 76 private String parameters; 77 78 private String eventType; 79 80 private String executeOnLoad; 81 82 private String defaultOptions; 83 84 private String postFunction; 85 86 private String preFunction; 87 88 private String errorFunction; 89 90 private String parser; 91 92 public String getBaseUrl() { 93 return baseUrl; 94 } 95 96 public void setBaseUrl(String baseUrl) { 97 this.baseUrl = baseUrl; 98 } 99 100 public String getErrorFunction() { 101 return errorFunction; 102 } 103 104 public void setErrorFunction(String errorFunction) { 105 this.errorFunction = errorFunction; 106 } 107 108 public String getEventType() { 109 return eventType; 110 } 111 112 public void setEventType(String eventType) { 113 this.eventType = eventType; 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 public String getExecuteOnLoad() { 181 return executeOnLoad; 182 } 183 184 public void setExecuteOnLoad(String executeOnLoad) { 185 this.executeOnLoad = executeOnLoad; 186 } 187 188 public String getDefaultOptions() { 189 return defaultOptions; 190 } 191 192 public void setDefaultOptions(String defaultOptions) { 193 this.defaultOptions = defaultOptions; 194 } 195 196 @Override 197 public int doStartTag() throws JspException { 198 this.baseUrl = (String ) ExpressionEvaluatorManager.evaluate("baseUrl", 200 this.baseUrl, String .class, this, super.pageContext); 201 this.source = (String ) ExpressionEvaluatorManager.evaluate("source", 202 this.source, String .class, this, super.pageContext); 203 this.target = (String ) ExpressionEvaluatorManager.evaluate("target", 204 this.target, String .class, this, super.pageContext); 205 this.parameters = (String ) ExpressionEvaluatorManager.evaluate( 206 "parameters", this.parameters, String .class, this, 207 super.pageContext); 208 209 if (this.emptyOptionValue != null) { 210 this.emptyOptionValue = (String ) ExpressionEvaluatorManager 211 .evaluate("emptyOptionValue", this.emptyOptionValue, 212 String .class, this, super.pageContext); 213 } 214 if (this.emptyOptionName != null) { 215 this.emptyOptionName = (String ) ExpressionEvaluatorManager 216 .evaluate("emptyOptionName", this.emptyOptionName, 217 String .class, this, super.pageContext); 218 } 219 220 if (this.var != null) { 222 this.var = (String ) ExpressionEvaluatorManager.evaluate("var", 223 this.var, String .class, this, super.pageContext); 224 } 225 if (this.attachTo != null) { 226 this.attachTo = (String ) ExpressionEvaluatorManager.evaluate( 227 "attachTo", this.attachTo, String .class, this, 228 super.pageContext); 229 } 230 if (this.eventType != null) { 231 this.eventType = (String ) ExpressionEvaluatorManager.evaluate( 232 "eventType", this.eventType, String .class, this, 233 super.pageContext); 234 } 235 if (this.defaultOptions != null) { 236 this.defaultOptions = (String ) ExpressionEvaluatorManager.evaluate( 237 "defaultOptions", this.defaultOptions, String .class, this, 238 super.pageContext); 239 } 240 if (this.preFunction != null) { 241 this.preFunction = (String ) ExpressionEvaluatorManager.evaluate( 242 "preFunction", this.preFunction, String .class, this, 243 super.pageContext); 244 } 245 if (this.postFunction != null) { 246 this.postFunction = (String ) ExpressionEvaluatorManager.evaluate( 247 "postFunction", this.postFunction, String .class, this, 248 super.pageContext); 249 } 250 if (this.errorFunction != null) { 251 this.errorFunction = (String ) ExpressionEvaluatorManager.evaluate( 252 "errorFunction", this.errorFunction, String .class, this, 253 super.pageContext); 254 } 255 return SKIP_BODY; 256 } 257 258 @Override 259 public int doEndTag() throws JspException { 260 OptionsBuilder options = new OptionsBuilder(); 261 options.add("source", this.source, true).add("target", this.target, 262 true).add("parameters", this.parameters, true); 263 if (this.executeOnLoad != null) 264 options.add("executeOnLoad", this.executeOnLoad, true); 265 if (this.eventType != null) 266 options.add("eventType", this.eventType, true); 267 if (this.defaultOptions != null) 268 options.add("defaultOptions", this.defaultOptions, true); 269 if (this.preFunction != null) 270 options.add("preFunction", this.preFunction, false); 271 if (this.postFunction != null) 272 options.add("postFunction", this.postFunction, false); 273 if (this.errorFunction != null) 274 options.add("errorFunction", this.errorFunction, false); 275 if (this.parser != null) 276 options.add("parser", this.parser, false); 277 if (this.doPost) 278 options.add("doPost", String.valueOf(this.doPost), false); 279 280 if (this.emptyOptionValue != null) 281 options.add("emptyOptionValue", emptyOptionValue, true); 282 if (this.emptyOptionName != null) 283 options.add("emptyOptionName", emptyOptionName, true); 284 285 StringBuffer script = new StringBuffer (); 286 script.append("<script type=\"text/javascript\">\n"); 287 if (StringUtils.isNotEmpty(this.var)) { 288 if (StringUtils.isNotEmpty(this.attachTo)) { 289 script.append(this.attachTo).append(".").append(this.var); 290 } else { 291 script.append("var ").append(this.var); 292 } 293 script.append(" = "); 294 } 295 script.append("new AjaxJspTag.Select(\n"); 296 script.append("\""); 297 script.append(this.baseUrl); 298 script.append("\", {\n"); 299 script.append(options.toString()); 300 script.append("});\n"); 301 script.append("</script>\n\n"); 302 303 JspWriter writer = pageContext.getOut(); 304 try { 305 writer.println(script); 306 } catch (IOException e) { 307 throw new JspException (e.getMessage()); 308 } 309 return EVAL_PAGE; 310 } 311 312 @Override 313 public void release() { 314 this.var = null; 315 this.attachTo = null; 316 this.baseUrl = null; 317 this.source = null; 318 this.target = null; 319 this.parameters = null; 320 this.eventType = null; 321 this.executeOnLoad = null; 322 this.defaultOptions = null; 323 this.preFunction = null; 324 this.postFunction = null; 325 this.errorFunction = null; 326 this.parser = null; 327 super.release(); 328 } 329 330 } 331
| Popular Tags
|