1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.components;
22
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25
26 import org.apache.struts2.views.annotations.StrutsTag;
27 import org.apache.struts2.views.annotations.StrutsTagAttribute;
28
29 import com.opensymphony.xwork2.util.ValueStack;
30
31 /***
32 * <!-- START SNIPPET: javadoc -->
33 * The tabbedpanel widget is primarily an AJAX component, where each tab can either be local content or remote
34 * content (refreshed each time the user selects that tab).</p>
35 * <!-- END SNIPPET: javadoc -->
36 *
37 * <p/> <b>Examples</b>
38 * <p/>
39 * <!-- START SNIPPET: exdesc -->
40 * The following is an example of a tabbedpanel and panel tag utilizing local and remote content.<p/>
41 * <!-- END SNIPPET: exdesc -->
42 * <pre>
43 * <!-- START SNIPPET: example -->
44 * <s:tabbedPanel id="test" >
45 * <s:div id="one" label="one" theme="ajax" labelposition="top" >
46 * This is the first pane<br/>
47 * <s:form>
48 * <s:textfield name="tt" label="Test Text"/> <br/>
49 * <s:textfield name="tt2" label="Test Text2"/>
50 * </s:form>
51 * </s:div>
52 * <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" >
53 * This is the remote tab
54 * </s:div>
55 * </s:tabbedPanel>
56 * <!-- END SNIPPET: example -->
57 * </pre>
58 *
59 */
60 @StrutsTag(name="tabbedPanel", tldTagClass="org.apache.struts2.views.jsp.ui.TabbedPanelTag", description="Render a tabbedPanel widget.")
61 public class TabbedPanel extends ClosingUIBean {
62 public static final String TEMPLATE = "tabbedpanel";
63 public static final String TEMPLATE_CLOSE = "tabbedpanel-close";
64 final private static String COMPONENT_NAME = TabbedPanel.class.getName();
65
66 protected String selectedTab;
67 protected String closeButton;
68 protected String doLayout ;
69
70 public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
71 super(stack, request, response);
72 }
73
74
75 protected void evaluateExtraParams() {
76 super.evaluateExtraParams();
77
78 if(selectedTab != null)
79 addParameter("selectedTab", findString(selectedTab));
80 if(closeButton != null)
81 addParameter("closeButton", findString(closeButton));
82 addParameter("doLayout", doLayout != null ? findValue(doLayout, Boolean.class) : Boolean.FALSE);
83 if(labelPosition != null) {
84
85 if(labelPosition.equalsIgnoreCase("left"))
86 labelPosition = "left-h";
87 if(labelPosition.equalsIgnoreCase("right"))
88 labelPosition = "right-h";
89 addParameter("labelPosition", null);
90 addParameter("labelPosition", labelPosition);
91 }
92 }
93
94 public String getDefaultOpenTemplate() {
95 return TEMPLATE;
96 }
97
98 protected String getDefaultTemplate() {
99 return TEMPLATE_CLOSE;
100 }
101
102 public String getComponentName() {
103 return COMPONENT_NAME;
104 }
105
106 @StrutsTagAttribute(description="The id to assign to the component.", required=true)
107 public void setId(String id) {
108
109 super.setId(id);
110 }
111
112
113 @StrutsTagAttribute(description=" The id of the tab that will be selected by default")
114 public void setSelectedTab(String selectedTab) {
115 this.selectedTab = selectedTab;
116 }
117
118 @StrutsTagAttribute(description="Where the close button will be placed, possible values are 'tab' and 'pane'")
119 public void setCloseButton(String closeButton) {
120 this.closeButton = closeButton;
121 }
122
123 @StrutsTagAttribute(description="If doLayout is false, the tab container's height equals the height of the currently selected tab", type="Boolean", defaultValue="false")
124 public void setDoLayout(String doLayout) {
125 this.doLayout = doLayout;
126 }
127 }