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 * If the useSelectedTabCookie attribute is set to true, the id of the selected tab is saved in a cookie on activation.
36 * When coming back to this view, the cookie is read and the tab will be activated again, unless an actual value for the
37 * selectedTab attribute is specified.</p>
38 * If you want to use the cookie feature, please be sure that you provide a unique id for your tabbedpanel component,
39 * since this will also be the identifying name component of the stored cookie.</p>
40 * <!-- END SNIPPET: javadoc -->
41 *
42 * <p/> <b>Examples</b>
43 * <p/>
44 * <!-- START SNIPPET: exdesc -->
45 * The following is an example of a tabbedpanel and panel tag utilizing local and remote content.<p/>
46 * <!-- END SNIPPET: exdesc -->
47 * <pre>
48 * <!-- START SNIPPET: example -->
49 * <s:tabbedPanel id="test" >
50 * <s:div id="one" label="one" theme="ajax" labelposition="top" >
51 * This is the first pane<br/>
52 * <s:form>
53 * <s:textfield name="tt" label="Test Text"/> <br/>
54 * <s:textfield name="tt2" label="Test Text2"/>
55 * </s:form>
56 * </s:div>
57 * <s:div id="three" label="remote" theme="ajax" href="/AjaxTest.action" >
58 * This is the remote tab
59 * </s:div>
60 * </s:tabbedPanel>
61 * <!-- END SNIPPET: example -->
62 * </pre>
63 *
64 */
65 @StrutsTag(name="tabbedPanel", tldTagClass="org.apache.struts2.views.jsp.ui.TabbedPanelTag", description="Render a tabbedPanel widget.")
66 public class TabbedPanel extends ClosingUIBean {
67 public static final String TEMPLATE = "tabbedpanel";
68 public static final String TEMPLATE_CLOSE = "tabbedpanel-close";
69 final private static String COMPONENT_NAME = TabbedPanel.class.getName();
70
71 protected String selectedTab;
72 protected String closeButton;
73 protected String doLayout ;
74 protected String templateCssPath;
75 protected String useSelectedTabCookie;
76
77 public TabbedPanel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
78 super(stack, request, response);
79 }
80
81
82 protected void evaluateExtraParams() {
83 super.evaluateExtraParams();
84
85 if(selectedTab != null)
86 addParameter("selectedTab", findString(selectedTab));
87 if(closeButton != null)
88 addParameter("closeButton", findString(closeButton));
89 addParameter("doLayout", doLayout != null ? findValue(doLayout, Boolean.class) : Boolean.FALSE);
90 if(labelPosition != null) {
91
92 if(labelPosition.equalsIgnoreCase("left"))
93 labelPosition = "left-h";
94 if(labelPosition.equalsIgnoreCase("right"))
95 labelPosition = "right-h";
96 addParameter("labelPosition", null);
97 addParameter("labelPosition", labelPosition);
98 }
99 if(templateCssPath != null)
100 addParameter("templateCssPath", findString(templateCssPath));
101 if(useSelectedTabCookie != null) {
102 addParameter("useSelectedTabCookie", findString(useSelectedTabCookie));
103 }
104 }
105
106 public String getDefaultOpenTemplate() {
107 return TEMPLATE;
108 }
109
110 protected String getDefaultTemplate() {
111 return TEMPLATE_CLOSE;
112 }
113
114 public String getComponentName() {
115 return COMPONENT_NAME;
116 }
117
118 @StrutsTagAttribute(description="The id to assign to the component.", required=true)
119 public void setId(String id) {
120
121 super.setId(id);
122 }
123
124
125 @StrutsTagAttribute(description=" The id of the tab that will be selected by default")
126 public void setSelectedTab(String selectedTab) {
127 this.selectedTab = selectedTab;
128 }
129
130 @StrutsTagAttribute(description="Where the close button will be placed, possible values are 'tab' and 'pane'")
131 public void setCloseButton(String closeButton) {
132 this.closeButton = closeButton;
133 }
134
135 @StrutsTagAttribute(description="If doLayout is false, the tab container's height equals the height of the currently selected tab", type="Boolean", defaultValue="false")
136 public void setDoLayout(String doLayout) {
137 this.doLayout = doLayout;
138 }
139
140 @StrutsTagAttribute(description="Template css path")
141 public void setTemplateCssPath(String templateCssPath) {
142 this.templateCssPath = templateCssPath;
143 }
144
145 @StrutsTagAttribute(required = false, defaultValue = "false", description = "If set to true, the id of the last selected " +
146 "tab will be stored in cookie. If the view is rendered, it will be tried to read this cookie and activate " +
147 "the corresponding tab on success, unless overridden by the selectedTab attribute. The cookie name is \"Struts2TabbedPanel_selectedTab_\"+id.")
148 public void setUseSelectedTabCookie( String useSelectedTabCookie ) {
149 this.useSelectedTabCookie = useSelectedTabCookie;
150 }
151 }