View Javadoc

1   /*
2    * $Id: Panel.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.components;
19  
20  import java.io.Writer;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import com.opensymphony.xwork2.util.ValueStack;
26  
27  /***
28   * <!-- START SNIPPET: javadoc -->
29   * Render a panel for tabbedPanel.</p>
30   * <!-- END SNIPPET: javadoc -->
31   *
32   * <p/> <b>Examples</b>
33   * See the example in {@link TabbedPanel}.
34   * <p/>
35   *
36   * @see TabbedPanel
37   *
38   * @s.tag name="panel" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ui.PanelTag"
39   * description="Render a panel for tabbedPanel"
40   */
41  public class Panel extends Div {
42  
43      public static final String TEMPLATE = "tab";
44      public static final String TEMPLATE_CLOSE = "tab-close";
45      public static final String COMPONENT_NAME = Panel.class.getName();
46  
47      protected String tabName;
48      protected String subscribeTopicName;
49      protected String remote;
50  
51      public Panel(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
52          super(stack, request, response);
53      }
54  
55      public String getDefaultOpenTemplate() {
56          return TEMPLATE;
57      }
58  
59      protected String getDefaultTemplate() {
60          return TEMPLATE_CLOSE;
61      }
62  
63      public boolean end(Writer writer, String body) {
64          TabbedPanel tabbedPanel = ((TabbedPanel) findAncestor(TabbedPanel.class));
65          subscribeTopicName = tabbedPanel.getTopicName();
66          tabbedPanel.addTab(this);
67  
68          return super.end(writer, body);
69      }
70  
71      public void evaluateExtraParams() {
72          super.evaluateExtraParams();
73  
74          if (tabName != null) {
75              addParameter("tabName", findString(tabName));
76          }
77  
78          if (subscribeTopicName != null) {
79              addParameter("subscribeTopicName", subscribeTopicName);
80          }
81  
82          if (remote != null && "true".equalsIgnoreCase(remote)) {
83              addParameter("remote", "true");
84          } else {
85              addParameter("remote", "false");
86          }
87      }
88  
89      public String getTabName() {
90          return findString(tabName);
91      }
92  
93      public String getComponentName() {
94          return COMPONENT_NAME;
95      }
96  
97      /***
98       * The text of the tab to display in the header tab list
99       * @s.tagattribute required="true"
100      */
101     public void setTabName(String tabName) {
102         this.tabName = tabName;
103     }
104 
105     /***
106      * Set subscribeTopicName attribute
107      * @s.tagattribute required="false"
108      */
109     public void setSubscribeTopicName(String subscribeTopicName) {
110         this.subscribeTopicName = subscribeTopicName;
111     }
112 
113     /***
114      * determines whether this is a remote panel (ajax) or a local panel (content loaded into visible/hidden containers)
115      * @s.tagattribute required="false" type="Boolean" default="false"
116      */
117     public void setRemote(String remote) {
118         this.remote = remote;
119     }
120 }