1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 * <s:tabbedPanel id="test2" theme="simple" >
42 * <s:panel id="left" tabName="left" theme="ajax">
43 * This is the left pane<br/>
44 * <s:form >
45 * <s:textfield name="tt" label="Test Text" /> <br/>
46 * <s:textfield name="tt2" label="Test Text2" />
47 * </s:form>
48 * </s:panel>
49 * <s:panel remote="true" href="/AjaxTest.action" id="ryh1" theme="ajax" tabName="remote one" />
50 * <s:panel id="middle" tabName="middle" theme="ajax">
51 * middle tab<br/>
52 * <s:form >
53 * <s:textfield name="tt" label="Test Text44" /> <br/>
54 * <s:textfield name="tt2" label="Test Text442" />
55 * </s:form>
56 * </s:panel>
57 * <s:panel remote="true" href="/AjaxTest.action" id="ryh21" theme="ajax" tabName="remote right" />
58 * </s:tabbedPanel>
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 * <link rel="stylesheet" type="text/css" href="<s:url value="/struts/tabs.css"/>">
73 * <link rel="stylesheet" type="text/css" href="<s:url value="/struts/niftycorners/niftyCorners.css"/>">
74 * <link rel="stylesheet" type="text/css" href="<s:url value="/struts/niftycorners/niftyPrint.css"/>" media="print">
75 * <script type="text/javascript" src="<s:url value="/struts/niftycorners/nifty.js"/>"></script>
76 * <script type="text/javascript">
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 * </script>
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
154 super.setId(id);
155 }
156 }