Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » components » [javadoc | source]
    1   /*
    2    * $Id: TabbedPanel.java 565265 2007-08-13 08:18:07Z 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    * 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    * &lt;s:tabbedPanel id=&quot;test&quot; &gt;
   50    *    &lt;s:div id=&quot;one&quot; label=&quot;one&quot; theme=&quot;ajax&quot; labelposition=&quot;top&quot; &gt;
   51    *        This is the first pane&lt;br/&gt;
   52    *        &lt;s:form&gt;
   53    *            &lt;s:textfield name=&quot;tt&quot; label=&quot;Test Text&quot;/&gt;  &lt;br/&gt;
   54    *            &lt;s:textfield name=&quot;tt2&quot; label=&quot;Test Text2&quot;/&gt;
   55    *        &lt;/s:form&gt;
   56    *    &lt;/s:div&gt;
   57    *    &lt;s:div id=&quot;three&quot; label=&quot;remote&quot; theme=&quot;ajax&quot; href=&quot;/AjaxTest.action&quot; &gt;
   58    *        This is the remote tab
   59    *    &lt;/s:div&gt;
   60    * &lt;/s:tabbedPanel&gt;
   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               //dojo has some weird name for label positions
   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           // This is required to override tld generation attributes to required=true
  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   }

Save This Page
Home » struts-2.1.8.1-src » org.apache » struts2 » components » [javadoc | source]