View Javadoc

1   /*
2    * $Id: TabbedPanel.java 497654 2007-01-19 00:21:57Z rgielen $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * &lt;s:tabbedPanel id=&quot;test&quot; &gt;
45   *    &lt;s:div id=&quot;one&quot; label=&quot;one&quot; theme=&quot;ajax&quot; labelposition=&quot;top&quot; &gt;
46   *        This is the first pane&lt;br/&gt;
47   *        &lt;s:form&gt;
48   *            &lt;s:textfield name=&quot;tt&quot; label=&quot;Test Text&quot;/&gt;  &lt;br/&gt;
49   *            &lt;s:textfield name=&quot;tt2&quot; label=&quot;Test Text2&quot;/&gt;
50   *        &lt;/s:form&gt;
51   *    &lt;/s:div&gt;
52   *    &lt;s:div id=&quot;three&quot; label=&quot;remote&quot; theme=&quot;ajax&quot; href=&quot;/AjaxTest.action&quot; &gt;
53   *        This is the remote tab
54   *    &lt;/s:div&gt;
55   * &lt;/s:tabbedPanel&gt;
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              //dojo has some weird name for label positions
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         // This is required to override tld generation attributes to required=true
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 }