KickJava   Java API By Example, From Geeks To Geeks.

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


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.taglibs.standard.lang.support.ExpressionEvaluatorManager;
25
26 /**
27  * Tag handler for individual page within a AJAX tabbed panel.
28  *
29  * @author Darren Spurgeon
30  * @version $Revision: 1.2 $ $Date: 2007/06/20 20:55:56 $ $Author: jenskapitza $
31  */

32 public class AjaxTabPageTag extends TagSupport JavaDoc {
33
34     private String JavaDoc caption;
35
36     private String JavaDoc baseUrl;
37
38     private String JavaDoc defaultTab;
39
40     private String JavaDoc parameters = "";
41
42     public String JavaDoc getCaption() {
43         return caption;
44     }
45
46     public void setCaption(String JavaDoc caption) {
47         this.caption = caption;
48     }
49
50     public String JavaDoc getDefaultTab() {
51         return defaultTab;
52     }
53
54     public void setDefaultTab(String JavaDoc defaultTab) {
55         this.defaultTab = defaultTab;
56     }
57
58     public String JavaDoc getParameters() {
59         return parameters;
60     }
61
62     public void setParameters(String JavaDoc parameters) {
63         this.parameters = parameters;
64     }
65
66     public String JavaDoc getBaseUrl() {
67         return baseUrl;
68     }
69
70     public void setBaseUrl(String JavaDoc baseUrl) {
71         this.baseUrl = baseUrl;
72     }
73
74     @Override JavaDoc
75     public int doStartTag() throws JspException JavaDoc {
76         // Required Properties
77
this.baseUrl = (String JavaDoc) ExpressionEvaluatorManager.evaluate("baseUrl",
78                 this.baseUrl, String JavaDoc.class, this, super.pageContext);
79         this.caption = (String JavaDoc) ExpressionEvaluatorManager.evaluate("caption",
80                 this.caption, String JavaDoc.class, this, super.pageContext);
81
82         // Optional Properties
83
if (this.parameters != null) {
84             this.parameters = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
85                     "parameters", this.parameters, String JavaDoc.class, this,
86                     super.pageContext);
87         }
88         if (this.defaultTab != null) {
89             this.defaultTab = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
90                     "defaultTab", this.defaultTab, String JavaDoc.class, this,
91                     super.pageContext);
92         }
93         return SKIP_BODY;
94     }
95
96     @Override JavaDoc
97     public int doEndTag() throws JspException JavaDoc {
98         AjaxTabPanelTag parent = (AjaxTabPanelTag) TagSupport
99                 .findAncestorWithClass(this, AjaxTabPanelTag.class);
100         StringBuffer JavaDoc script = new StringBuffer JavaDoc();
101         if (Boolean.valueOf(this.defaultTab).booleanValue()) {
102             script.append("<li><a class=\"");
103             script.append(parent.getCurrentStyleClass());
104             script.append("\" ");
105             parent.setDefaultTabBaseUrl(this.baseUrl);
106             parent.setDefaultTabParameters(this.parameters);
107         } else {
108             script.append("<li><a ");
109         }
110         script.append("href=\"javascript://nop/\" onclick=\"executeAjaxTab_");
111         script.append(parent.getPanelStyleId());
112         script.append("(this,'");
113         script.append(parent.getCurrentStyleClass());
114         script.append("', '");
115         script.append(this.baseUrl);
116         script.append("', '");
117         script.append(this.parameters);
118         script.append("'); return false;\">");
119         script.append(this.caption);
120         script.append("</a></li>");
121         JspWriter JavaDoc writer = pageContext.getOut();
122         try {
123             writer.println(script);
124         } catch (IOException JavaDoc e) {
125             throw new JspException JavaDoc(e.getMessage());
126         }
127         return EVAL_PAGE;
128     }
129
130     @Override JavaDoc
131     public void release() {
132         this.caption = null;
133         this.baseUrl = null;
134         this.defaultTab = null;
135         this.parameters = null;
136         super.release();
137     }
138
139 }
140
Popular Tags