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