View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.custom.panelstack;
20  
21  import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
22  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  import java.io.IOException;
27  
28  
29  /**
30   * @JSFRenderer
31   *   renderKitId = "HTML_BASIC" 
32   *   family = "javax.faces.Panel"
33   *   type = "org.apache.myfaces.PanelStack"
34   * 
35   * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
36   * @version $Revision: 990487 $ $Date: 2010-08-28 23:25:48 -0500 (Sat, 28 Aug 2010) $
37   */
38  public class HtmlPanelStackRenderer extends HtmlRenderer
39  {
40  
41  
42      public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException
43      {
44      }
45  
46  
47      public boolean getRendersChildren()
48      {
49          return true;
50      }
51  
52  
53      public void encodeChildren(FacesContext facescontext, UIComponent uicomponent) throws IOException
54      {
55      }
56  
57  
58      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException
59      {
60          RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlPanelStack.class);
61  
62          HtmlPanelStack panelStack = (HtmlPanelStack) uiComponent;
63          String selectedPanel = panelStack.getSelectedPanel();
64          UIComponent childToRender = null;
65  
66          if (selectedPanel != null && selectedPanel.length() > 0)
67          {
68              // render the selected child
69              childToRender = panelStack.findComponent(selectedPanel);
70              if (childToRender == null)
71              {
72                  // if not found, render the first child
73                  if (panelStack.getChildCount() > 0) {
74                      childToRender = (UIComponent) panelStack.getChildren().get(0);
75                  }
76              }
77          }
78          else
79          {
80              // render the first child
81              if (panelStack.getChildCount() > 0) {
82                  childToRender = (UIComponent) panelStack.getChildren().get(0);
83              }
84          }
85  
86          if (childToRender != null)
87          {
88              RendererUtils.renderChild(facesContext, childToRender);
89          }
90      }
91  
92  }