KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.faces.component.html.HtmlPanelGroup;
19 import javax.faces.context.FacesContext;
20
21 import javax.faces.el.ValueBinding;
22
23
24 /**
25  * Manage a stack of JSF components and allow for one child component to be choosen for rendering. The behaviour
26  * is similar to the CardLayout of Java Swing. Property <code>selectedPanel</code> defines the id of the child
27  * to be rendered. If no child panel is selected or if the selected panel can not be found the first child is rendered.
28  *
29  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
30  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:57 $
31  * $Log: HtmlPanelStack.java,v $
32  * Revision 1.3 2004/10/13 11:50:57 matze
33  * renamed packages to org.apache
34  *
35  * Revision 1.2 2004/09/01 18:32:55 mwessendorf
36  * Organize Imports
37  *
38  * Revision 1.1 2004/08/15 22:42:11 o_rossmueller
39  * new custom component: HtmlPanelStack
40  *
41  *
42  */

43 public class HtmlPanelStack extends HtmlPanelGroup
44 {
45
46     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.HtmlPanelStack";
47     public static final String JavaDoc COMPONENT_FAMILY = "javax.faces.Panel";
48     private static final String JavaDoc DEFAULT_RENDERER_TYPE = "org.apache.myfaces.PanelStack";
49
50     private String JavaDoc selectedPanel = null;
51
52     public HtmlPanelStack()
53     {
54         setRendererType(DEFAULT_RENDERER_TYPE);
55     }
56
57     public String JavaDoc getFamily()
58     {
59         return COMPONENT_FAMILY;
60     }
61
62     public void setSelectedPanel(String JavaDoc selectedPanel)
63     {
64         this.selectedPanel = selectedPanel;
65     }
66
67     public String JavaDoc getSelectedPanel()
68     {
69         if (selectedPanel != null) return selectedPanel;
70         ValueBinding vb = getValueBinding("selectedPanel");
71         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
72     }
73
74     public Object JavaDoc saveState(FacesContext context)
75     {
76         Object JavaDoc values[] = new Object JavaDoc[2];
77         values[0] = super.saveState(context);
78         values[1] = selectedPanel;
79         return ((Object JavaDoc) (values));
80     }
81
82     public void restoreState(FacesContext context, Object JavaDoc state)
83     {
84         Object JavaDoc values[] = (Object JavaDoc[])state;
85         super.restoreState(context, values[0]);
86         selectedPanel = (String JavaDoc)values[1];
87     }
88 }
89
Popular Tags