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.taglibs.standard.lang.support.ExpressionEvaluatorManager; 25 26 33 public class AjaxEditorTag extends TagSupport { 34 private boolean showAcceptButton; 35 36 private String acceptText; 37 38 private boolean showCancelLink; 39 40 private String cancelText; 41 42 private String savingText; 43 44 private String mouseOverText; 45 46 private String styleId; 47 48 private String rows; 49 50 private String columns; 51 52 private String postFunction; 53 54 private String errorFunction; 55 56 private String preFunction; 57 58 private String highlightColor; 59 60 private String target; 61 62 private String baseUrl; 63 64 @Override  65 public int doStartTag() throws JspException { 66 this.baseUrl = (String ) ExpressionEvaluatorManager.evaluate("baseUrl", 68 this.baseUrl, String .class, this, super.pageContext); 69 this.target = (String ) ExpressionEvaluatorManager.evaluate("target", 70 this.target, String .class, this, super.pageContext); 71 72 if (showAcceptButton && this.acceptText != null) { 74 this.acceptText = (String ) ExpressionEvaluatorManager.evaluate( 75 "acceptText", this.acceptText, String .class, this, 76 super.pageContext); 77 } 78 if (showCancelLink && this.cancelText != null) { 79 this.cancelText = (String ) ExpressionEvaluatorManager.evaluate( 80 "cancelText", this.cancelText, String .class, this, 81 super.pageContext); 82 } 83 if (this.savingText != null) { 84 this.savingText = (String ) ExpressionEvaluatorManager.evaluate( 85 "savingText", this.savingText, String .class, this, 86 super.pageContext); 87 } 88 if (this.mouseOverText != null) { 89 this.mouseOverText = (String ) ExpressionEvaluatorManager.evaluate( 90 "mouseOverText", this.mouseOverText, String .class, this, 91 super.pageContext); 92 } 93 if (this.styleId != null) { 94 this.styleId = (String ) ExpressionEvaluatorManager.evaluate( 95 "styleId", this.styleId, String .class, this, 96 super.pageContext); 97 } 98 if (this.rows != null) { 99 this.rows = (String ) ExpressionEvaluatorManager.evaluate("rows", 100 this.rows, String .class, this, super.pageContext); 101 } 102 if (this.columns != null) { 103 this.columns = (String ) ExpressionEvaluatorManager.evaluate( 104 "columns", this.columns, String .class, this, 105 super.pageContext); 106 } 107 if (this.postFunction != null) { 108 this.postFunction = (String ) ExpressionEvaluatorManager.evaluate( 109 "postFunction", this.postFunction, String .class, this, 110 super.pageContext); 111 } 112 if (this.errorFunction != null) { 113 this.errorFunction = (String ) ExpressionEvaluatorManager.evaluate( 114 "errorFunction", this.errorFunction, String .class, this, 115 super.pageContext); 116 } 117 if (this.preFunction != null) { 118 this.preFunction = (String ) ExpressionEvaluatorManager.evaluate( 119 "preFunction", this.preFunction, String .class, this, 120 super.pageContext); 121 } 122 if (this.highlightColor != null) { 123 this.highlightColor = (String ) ExpressionEvaluatorManager.evaluate( 124 "highlightColor", this.highlightColor, String .class, this, 125 super.pageContext); 126 } 127 128 return SKIP_BODY; 129 } 130 131 @Override  132 public int doEndTag() throws JspException { 133 OptionsBuilder options = new OptionsBuilder(); 134 135 options.add("okButton", this.showAcceptButton ? "true" : "false", true); 136 if (this.showAcceptButton && this.acceptText != null) 137 options.add("okText", this.acceptText, true); 138 139 options.add("cancelLink", this.showCancelLink ? "true" : "false", true); 140 if (this.showCancelLink && this.cancelText != null) 141 options.add("cancelText", this.cancelText, true); 142 143 if (this.savingText != null) 144 options.add("savingText", this.savingText, true); 145 if (this.mouseOverText != null) 146 options.add("clickToEditText", this.mouseOverText, true); 147 if (this.preFunction != null) 148 options.add("callback", this.preFunction, false); 149 if (this.postFunction != null) 150 options.add("onComplete", this.postFunction, false); 151 if (this.errorFunction != null) 152 options.add("onFailure", this.errorFunction, false); 153 if (this.styleId != null) 154 options.add("formId", this.styleId, true); 155 if (this.rows != null) 156 options.add("rows", this.rows, true); 157 if (this.columns != null) 158 options.add("cols", this.columns, true); 159 if (this.highlightColor != null) 160 options.add("highlightColor", this.highlightColor, true); 161 162 StringBuffer script = new StringBuffer (); 163 script.append("<script type=\"text/javascript\">\n"); 164 script.append("var editor_").append(target); 165 script.append(" = new Ajax.InPlaceEditor(\""); 166 script.append(target); 167 script.append("\", \""); 168 script.append(this.baseUrl); 169 script.append("\", {\n"); 170 script.append(options.toString()); 171 script.append("});\n"); 172 script.append("</script>\n\n"); 173 174 JspWriter writer = pageContext.getOut(); 175 try { 176 writer.println(script); 177 } catch (IOException e) { 178 throw new JspException (e.getMessage()); 179 } 180 return EVAL_PAGE; 181 } 182 183 public String getAcceptText() { 184 return acceptText; 185 } 186 187 public void setAcceptText(String acceptText) { 188 this.acceptText = acceptText; 189 } 190 191 public String getCancelText() { 192 return cancelText; 193 } 194 195 public void setCancelText(String cancelText) { 196 this.cancelText = cancelText; 197 } 198 199 public String getColumns() { 200 return columns; 201 } 202 203 public void setColumns(String columns) { 204 this.columns = columns; 205 } 206 207 public String getErrorFunction() { 208 return errorFunction; 209 } 210 211 public void setErrorFunction(String errorFunction) { 212 this.errorFunction = errorFunction; 213 } 214 215 public String getHighlightColor() { 216 return highlightColor; 217 } 218 219 public void setHighlightColor(String highlightColor) { 220 this.highlightColor = highlightColor; 221 } 222 223 public String getMouseOverText() { 224 return mouseOverText; 225 } 226 227 public void setMouseOverText(String mouseOverText) { 228 this.mouseOverText = mouseOverText; 229 } 230 231 public String getPostFunction() { 232 return postFunction; 233 } 234 235 public void setPostFunction(String postFunction) { 236 this.postFunction = postFunction; 237 } 238 239 public String getPreFunction() { 240 return preFunction; 241 } 242 243 public void setPreFunction(String prerFunction) { 244 this.preFunction = prerFunction; 245 } 246 247 public String getRows() { 248 return rows; 249 } 250 251 public void setRows(String rows) { 252 this.rows = rows; 253 } 254 255 public String getSavingText() { 256 return savingText; 257 } 258 259 public void setSavingText(String savingText) { 260 this.savingText = savingText; 261 } 262 263 public boolean isShowAcceptButton() { 264 return showAcceptButton; 265 } 266 267 public void setShowAcceptButton(boolean showAcceptButton) { 268 this.showAcceptButton = showAcceptButton; 269 } 270 271 public boolean isShowCancelLink() { 272 return showCancelLink; 273 } 274 275 public void setShowCancelLink(boolean showCancelLink) { 276 this.showCancelLink = showCancelLink; 277 } 278 279 public String getStyleId() { 280 return styleId; 281 } 282 283 public void setStyleId(String styleId) { 284 this.styleId = styleId; 285 } 286 287 public String getBaseUrl() { 288 return baseUrl; 289 } 290 291 public void setBaseUrl(String baseURL) { 292 this.baseUrl = baseURL; 293 } 294 295 public String getTarget() { 296 return target; 297 } 298 299 public void setTarget(String target) { 300 this.target = target; 301 } 302 } 303 | Popular Tags |