KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > panelstack > HtmlPanelStackRenderer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.panelstack;
17
18 import org.apache.myfaces.renderkit.RendererUtils;
19 import org.apache.myfaces.renderkit.html.HtmlRenderer;
20
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import java.io.IOException JavaDoc;
24
25
26 /**
27  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
28  * @version $Revision: 1.5 $ $Date: 2004/10/13 11:50:57 $
29  * $Log: HtmlPanelStackRenderer.java,v $
30  * Revision 1.5 2004/10/13 11:50:57 matze
31  * renamed packages to org.apache
32  *
33  * Revision 1.4 2004/09/01 18:32:55 mwessendorf
34  * Organize Imports
35  *
36  * Revision 1.3 2004/08/15 23:16:36 o_rossmueller
37  * do not overwrite decode
38  *
39  * Revision 1.2 2004/08/15 23:12:54 o_rossmueller
40  * processDecodes on selected child
41  *
42  * Revision 1.1 2004/08/15 22:42:11 o_rossmueller
43  * new custom component: HtmlPanelStack
44  *
45  */

46 public class HtmlPanelStackRenderer extends HtmlRenderer
47 {
48
49
50     public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException JavaDoc
51     {
52     }
53
54
55     public boolean getRendersChildren()
56     {
57         return true;
58     }
59
60
61     public void encodeChildren(FacesContext facescontext, UIComponent uicomponent) throws IOException JavaDoc
62     {
63     }
64
65
66     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException JavaDoc
67     {
68         RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlPanelStack.class);
69
70         HtmlPanelStack panelStack = (HtmlPanelStack) uiComponent;
71         String JavaDoc selectedPanel = panelStack.getSelectedPanel();
72         UIComponent childToRender = null;
73
74         if (selectedPanel == null)
75         {
76             // render the first child
77
if (panelStack.getChildCount() > 0) {
78                 childToRender = (UIComponent) panelStack.getChildren().get(0);
79             }
80         } else
81         {
82             // render the selected child
83
childToRender = panelStack.findComponent(selectedPanel);
84             if (childToRender == null)
85             {
86                 // if not found, render the first child
87
if (panelStack.getChildCount() > 0) {
88                     childToRender = (UIComponent) panelStack.getChildren().get(0);
89                 }
90             }
91         }
92
93         if (childToRender != null)
94         {
95             RendererUtils.renderChild(facesContext, childToRender);
96         }
97     }
98
99 }
100
Popular Tags