View Javadoc

1   /*
2    * $Id: TabbedPanel.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.components;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.http.HttpServletResponse;
25  
26  import com.opensymphony.xwork2.util.ValueStack;
27  
28  /***
29   * <!-- START SNIPPET: javadoc -->
30   * The tabbedpanel widget is primarily an AJAX component, where each tab can either be local content or remote
31   * content (refreshed each time the user selects that tab).</p>
32   * <!-- END SNIPPET: javadoc -->
33   *
34   * <p/> <b>Examples</b>
35   * <p/>
36   * <!-- START SNIPPET: exdesc -->
37   * The following is an example of a tabbedpanel and panel tag utilizing local and remote content.<p/>
38   * <!-- END SNIPPET: exdesc -->
39   * <pre>
40   * <!-- START SNIPPET: example -->
41   * &lt;s:tabbedPanel id="test2" theme="simple" &gt;
42   *     &lt;s:panel id="left" tabName="left" theme="ajax"&gt;
43   *         This is the left pane&lt;br/&gt;
44   *         &lt;s:form &gt;
45   *             &lt;s:textfield name="tt" label="Test Text" /&gt;  &lt;br/&gt;
46   *             &lt;s:textfield name="tt2" label="Test Text2" /&gt;
47   *         &lt;/s:form&gt;
48   *     &lt;/s:panel&gt;
49   *     &lt;s:panel remote="true" href="/AjaxTest.action" id="ryh1" theme="ajax" tabName="remote one" /&gt;
50   *     &lt;s:panel id="middle" tabName="middle" theme="ajax"&gt;
51   *         middle tab&lt;br/&gt;
52   *         &lt;s:form &gt;
53   *             &lt;s:textfield name="tt" label="Test Text44" /&gt;  &lt;br/&gt;
54   *             &lt;s:textfield name="tt2" label="Test Text442" /&gt;
55   *         &lt;/s:form&gt;
56   *     &lt;/s:panel&gt;
57   *     &lt;s:panel remote="true" href="/AjaxTest.action"  id="ryh21" theme="ajax" tabName="remote right" /&gt;
58   * &lt;/s:tabbedPanel&gt;
59   * <!-- END SNIPPET: example -->
60   * </pre>
61   *
62   * <p/> <b>Additional Configuration</b>
63   *
64   * <!-- START SNIPPET: exdesc2 -->
65   * If you are looking for the "nifty" rounded corner look, there is additional configuration. This assumes
66   * that the background color of the tabs is white. If you are using a different color, please modify the
67   * parameter in the Rounded() method.<p/>
68   * <!-- END SNIPPET: exdesc2 -->
69   *
70   * <pre>
71   * <!-- START SNIPPET: example2 -->
72   * &lt;link rel="stylesheet" type="text/css" href="&lt;s:url value="/struts/tabs.css"/&gt;"&gt;
73   * &lt;link rel="stylesheet" type="text/css" href="&lt;s:url value="/struts/niftycorners/niftyCorners.css"/&gt;"&gt;
74   * &lt;link rel="stylesheet" type="text/css" href="&lt;s:url value="/struts/niftycorners/niftyPrint.css"/&gt;" media="print"&gt;
75   * &lt;script type="text/javascript" src="&lt;s:url value="/struts/niftycorners/nifty.js"/&gt;"&gt;&lt;/script&gt;
76   * &lt;script type="text/javascript"&gt;
77   *     dojo.event.connect(window, "onload", function() {
78   *         if (!NiftyCheck())
79   *             return;
80   *         Rounded("li.tab_selected", "top", "white", "transparent", "border #ffffffS");
81   *         Rounded("li.tab_unselected", "top", "white", "transparent", "border #ffffffS");
82   *         // "white" needs to be replaced with the background color
83   *     });
84   * &lt;/script&gt;
85   * <!-- END SNIPPET: example2 -->
86   * </pre>
87   *
88   * <b>Important:</b> Be sure to setup the page containing this tag to be Configured for AJAX
89   *
90   * @see Panel
91   *
92   * @s.tag name="tabbedPanel" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ui.TabbedPanelTag"
93   * description="Render a tabbedPanel widget."
94   */
95  public class TabbedPanel extends ClosingUIBean {
96      public static final String TEMPLATE = "tabbedpanel";
97      public static final String TEMPLATE_CLOSE = "tabbedpanel-close";
98      final private static String COMPONENT_NAME = TabbedPanel.class.getName();
99  
100     protected List tabs = new ArrayList();
101 
102     public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
103         super(stack, request, response);
104     }
105 
106     /***
107      * Add a new panel to be rendered.
108      *
109      * @param pane a new panel to be rendered
110      */
111     public void addTab(Panel pane) {
112         tabs.add(pane);
113     }
114 
115     /***
116      * Get the list of panel tabs for this tab panel.
117      *
118      * @return the list of panel tabs for this tab panel
119      */
120     public List getTabs() {
121         return tabs;
122     }
123 
124     public String getTopicName() {
125         return "topic_tab_" + id + "_selected";
126     }
127 
128     protected void evaluateExtraParams() {
129         super.evaluateExtraParams();
130 
131         addParameter("topicName", "topic_tab_" + id + "_selected");
132         addParameter("tabs", tabs);
133 
134     }
135 
136     public String getDefaultOpenTemplate() {
137         return TEMPLATE;
138     }
139 
140     protected String getDefaultTemplate() {
141         return TEMPLATE_CLOSE;
142     }
143 
144     public String getComponentName() {
145         return COMPONENT_NAME;
146     }
147 
148     /***
149      * The id to assign to the component.
150      * @s.tagattribute required="true" type="String"
151      */
152     public void setId(String id) {
153         // This is required to override tld generation attributes to required=true
154         super.setId(id);
155     }
156 }