View Javadoc

    1   /*
    2    * $Id: TabbedPanel.java 508570 2007-02-16 20:42:17Z musachy $
    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      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              //dojo has some weird name for label positions
    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         // This is required to override tld generation attributes to required=true
    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 }