1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2WebGui library.
13 *
14 * The Initial Owner of the Original Code is Power Of Two S.R.L.
15 * Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16 * All Rights Reserved.
17 *
18 * Contributor(s):
19 * Henner.Kollmann
20 * - provides code to automatically set the required selectedTab attribute;
21 * - uses the TryCatchFinally interface; reset the selected Tab attribute
22 * into doFinally() (necessary for tomcat 4.1.x);
23 */
24
25 package com.pow2.webgui.taglib;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.jsp.JspTagException;
29 import javax.servlet.jsp.tagext.TryCatchFinally;
30
31 import com.pow2.util.Util;
32 import com.pow2.webgui.WidgetFactory;
33 import com.pow2.webgui.contentprovider.BaseContentProvider;
34 import com.pow2.webgui.tabbedselector.TabbedSelector;
35 import com.pow2.webgui.tabbedselector.TabbedSelectorUtil;
36
37
38 /***
39 * TabbedSelectorTag class.
40 *
41 * @author Luca Fossato
42 * @created 11 June 2001
43 */
44 public class TabbedSelectorTag extends TabbedSelector implements TryCatchFinally
45 {
46 private WidgetFactory wf = null;
47 private TabbedSelector ts = null;
48
49
50 /***
51 * Gets the TabbedPanel attribute of this tag.
52 *
53 * @return the TabbedPanel attribute of this tag.
54 */
55 public TabbedSelector getTabbedSelector()
56 {
57 return ts;
58 }
59
60
61 /***
62 * @return Description of the Return Value
63 * @exception JspTagException Description of the Exception
64 */
65 public int doStartTag() throws JspTagException
66 {
67
68
69 try
70 {
71
72
73
74 if (getSelectedTab() == null)
75 {
76 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
77 String selTab = TabbedSelectorUtil.getSelectedTabParamValue(request, getName());
78
79 if (!Util.isNull(selTab))
80 setSelectedTab(selTab);
81 }
82
83 wf = WidgetFactory.instance();
84 ts = (TabbedSelector)wf.getWidget(TabbedSelector.KEY);
85 ts.updateAttributes(this);
86 ts.setWidgetDrawer(drawer);
87 }
88 catch(Exception e)
89 {
90 cat.error("::doStartTag - cannot retrieve the widget having key [" + TabbedSelector.KEY + "]");
91 throw new JspTagException(e.getMessage());
92 }
93
94 return EVAL_BODY_BUFFERED;
95 }
96
97
98 /***
99 * @return Description of the Return Value
100 * @exception JspTagException Description of the Exception
101 */
102 public int doEndTag() throws JspTagException
103 {
104 try
105 {
106
107 if (!Util.isNull(contentProviderName))
108 {
109 ts.setContentProvider(contentProviderName);
110 BaseContentProvider cp = ts.getContentProvider();
111
112 if (cp != null)
113 TagUtil.setContentProviderData(cp, pageContext);
114 }
115 }
116 catch (Exception e)
117 {
118 cat.error("::doStartTag - cannot set the widget content provider", e);
119 throw new JspTagException(e.getMessage());
120 }
121
122 if (bodyContent != null)
123 {
124 try
125 {
126 bodyContent.getEnclosingWriter().print(ts.draw());
127 }
128 catch(Exception e)
129 {
130 cat.error("::doAfterBody - drawing error", e);
131 throw new JspTagException(e.getMessage());
132 }
133 }
134
135 return EVAL_PAGE;
136 }
137
138
139 /***
140 * Reset selected Tab. necessary for tomcat 4.1.x.
141 * <br>
142 * 2002118 Henner.Kollmann@aucos.de
143 */
144 public void doFinally()
145 {
146 setSelectedTab(null);
147 removeTabs();
148 }
149
150
151 /***
152 * DOCUMENT ME!
153 * <br>
154 * 2002118 Henner.Kollmann@aucos.de
155 *
156 * @param t DOCUMENT ME!
157 * @throws Throwable DOCUMENT ME!
158 */
159 public void doCatch(Throwable t) throws Throwable
160 {
161 cat.error("::doCatch - exception", t);
162 throw t;
163 }
164 }