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 protected String templateCssPath;
70
71 public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
72 super(stack, request, response);
73 }
74
75
76 protected void evaluateExtraParams() {
77 super.evaluateExtraParams();
78
79 if(selectedTab != null)
80 addParameter("selectedTab", findString(selectedTab));
81 if(closeButton != null)
82 addParameter("closeButton", findString(closeButton));
83 addParameter("doLayout", doLayout != null ? findValue(doLayout, Boolean.class) : Boolean.FALSE);
84 if(labelPosition != null) {
85
86 if(labelPosition.equalsIgnoreCase("left"))
87 labelPosition = "left-h";
88 if(labelPosition.equalsIgnoreCase("right"))
89 labelPosition = "right-h";
90 addParameter("labelPosition", null);
91 addParameter("labelPosition", labelPosition);
92 }
93 if(templateCssPath != null)
94 addParameter("templateCssPath", findString(templateCssPath));
95 }
96
97 public String getDefaultOpenTemplate() {
98 return TEMPLATE;
99 }
100
101 protected String getDefaultTemplate() {
102 return TEMPLATE_CLOSE;
103 }
104
105 public String getComponentName() {
106 return COMPONENT_NAME;
107 }
108
109 @StrutsTagAttribute(description="The id to assign to the component.", required=true)
110 public void setId(String id) {
111
112 super.setId(id);
113 }
114
115
116 @StrutsTagAttribute(description=" The id of the tab that will be selected by default")
117 public void setSelectedTab(String selectedTab) {
118 this.selectedTab = selectedTab;
119 }
120
121 @StrutsTagAttribute(description="Where the close button will be placed, possible values are 'tab' and 'pane'")
122 public void setCloseButton(String closeButton) {
123 this.closeButton = closeButton;
124 }
125
126 @StrutsTagAttribute(description="If doLayout is false, the tab container's height equals the height of the currently selected tab", type="Boolean", defaultValue="false")
127 public void setDoLayout(String doLayout) {
128 this.doLayout = doLayout;
129 }
130
131 @StrutsTagAttribute(description="Template css path")
132 public void setTemplateCssPath(String templateCssPath) {
133 this.templateCssPath = templateCssPath;
134 }
135 }