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 31 public class AjaxServerCallback extends TagSupport { 32 private String parser; 33 private String url; 34 private String errorFunction; 35 private String postFunction; 36 private String preFunction; 37 private boolean plainText; 38 39 @Override 40 public int doStartTag() throws JspException { 41 return SKIP_BODY; 43 } 44 45 @Override 46 public int doEndTag() throws JspException { 47 JspWriter writer = pageContext.getOut(); 49 OptionsBuilder options = new OptionsBuilder(); 51 52 options.add("plainText", String.valueOf(this.plainText), false); 53 54 if (this.preFunction != null) 55 options.add("preFunction", this.preFunction, false); 56 if (this.postFunction != null) 57 options.add("postFunction", this.postFunction, false); 58 if (this.errorFunction != null) 59 options.add("errorFunction", this.errorFunction, false); 60 if (this.parser != null) 61 options.add("parser", this.parser, false); 62 63 StringBuffer script = new StringBuffer (); 64 script.append("<script type=\"text/javascript\">\n"); 65 script.append("new AjaxJspTag.Callback('" + this.url + "',{" 66 + options.toString() + "});\n"); 67 script.append("</script>\n"); 68 try { 69 writer.println(script); 70 } catch (IOException e) { 71 throw new JspException (e.getMessage()); 72 } 73 74 return EVAL_PAGE; 75 } 76 77 public String getParser() { 78 return parser; 79 } 80 81 public void setParser(String parser) { 82 this.parser = parser; 83 } 84 85 public String getUrl() { 86 return url; 87 } 88 89 public void setUrl(String url) { 90 this.url = url; 91 } 92 93 public String getErrorFunction() { 94 return errorFunction; 95 } 96 97 public void setErrorFunction(String errorFunction) { 98 this.errorFunction = errorFunction; 99 } 100 101 public String getPostFunction() { 102 return postFunction; 103 } 104 105 public void setPostFunction(String postFunction) { 106 this.postFunction = postFunction; 107 } 108 109 public String getPreFunction() { 110 return preFunction; 111 } 112 113 public void setPreFunction(String preFunction) { 114 this.preFunction = preFunction; 115 } 116 117 public boolean isPlainText() { 118 return plainText; 119 } 120 121 public void setPlainText(boolean plainText) { 122 this.plainText = plainText; 123 } 124 } 125 | Popular Tags |