KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ajaxtags > tags > AjaxServerCallback


1 /**
2  * Copyright 2007 Jens Kapitza
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.ajaxtags.tags;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.JspWriter JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 /**
25  * Realize a Server Update
26  *
27  * @author Jens Kapitza
28  *
29  * @version $Revision: 1.1 $ $Date: 2007/06/23 18:36:51 $ $Author: jenskapitza $
30  */

31 public class AjaxServerCallback extends TagSupport JavaDoc {
32     private String JavaDoc parser;
33     private String JavaDoc url;
34     private String JavaDoc errorFunction;
35     private String JavaDoc postFunction;
36     private String JavaDoc preFunction;
37     private boolean plainText;
38
39     @Override JavaDoc
40     public int doStartTag() throws JspException JavaDoc {
41         // kein body
42
return SKIP_BODY;
43     }
44
45     @Override JavaDoc
46     public int doEndTag() throws JspException JavaDoc {
47         // nun das JS erzeugen
48
JspWriter JavaDoc writer = pageContext.getOut();
49         // vertige JS function aufrufen!
50
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 JavaDoc script = new StringBuffer JavaDoc();
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 JavaDoc e) {
71             throw new JspException JavaDoc(e.getMessage());
72         }
73
74         return EVAL_PAGE;
75     }
76
77     public String JavaDoc getParser() {
78         return parser;
79     }
80
81     public void setParser(String JavaDoc parser) {
82         this.parser = parser;
83     }
84
85     public String JavaDoc getUrl() {
86         return url;
87     }
88
89     public void setUrl(String JavaDoc url) {
90         this.url = url;
91     }
92
93     public String JavaDoc getErrorFunction() {
94         return errorFunction;
95     }
96
97     public void setErrorFunction(String JavaDoc errorFunction) {
98         this.errorFunction = errorFunction;
99     }
100
101     public String JavaDoc getPostFunction() {
102         return postFunction;
103     }
104
105     public void setPostFunction(String JavaDoc postFunction) {
106         this.postFunction = postFunction;
107     }
108
109     public String JavaDoc getPreFunction() {
110         return preFunction;
111     }
112
113     public void setPreFunction(String JavaDoc 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