KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright 2005 Darren L. Spurgeon
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 import org.apache.commons.lang.StringUtils;
25 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
26
27 /**
28  * Tag handler for AJAX tabbed panel.
29  *
30  * @author Darren Spurgeon
31  * @version $Revision: 1.2 $ $Date: 2007/06/20 20:55:56 $ $Author: jenskapitza $
32  */

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