KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > component > BaseComponent


1 /*
2  * Copyright 2002-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
17 package org.apache.struts.faces.component;
18
19
20 import javax.faces.component.UIOutput;
21 import javax.faces.context.FacesContext;
22 import javax.faces.el.ValueBinding;
23
24
25 /**
26  * <p>Custom component that replaces the Struts
27  * <code>&lt;html:base&gt;</code> tag.</p>
28  */

29
30 public class BaseComponent extends UIOutput {
31
32
33     // ------------------------------------------------------------ Constructors
34

35
36     /**
37      * <p>Create a new {@link BaseComponent} with default properties.</p>
38      */

39     public BaseComponent() {
40
41         super();
42         setRendererType("org.apache.struts.faces.Base");
43
44     }
45
46
47     // ------------------------------------------------------ Instance Variables
48

49
50     /**
51      * <p>Target frame.</p>
52      */

53     private String JavaDoc target = null;
54
55
56     // ---------------------------------------------------- Component Properties
57

58
59     /**
60      * <p>Return the component family to which this component belongs.</p>
61      */

62     public String JavaDoc getFamily() {
63
64         return "org.apache.struts.faces.Base";
65
66     }
67
68
69     /**
70      * <p>Return the target frame.</p>
71      */

72     public String JavaDoc getTarget() {
73
74         ValueBinding vb = getValueBinding("target");
75         if (vb != null) {
76             return (String JavaDoc) vb.getValue(getFacesContext());
77         } else {
78             return target;
79         }
80
81     }
82
83
84     /**
85      * <p>Set the target frame.</p>
86      *
87      * @param target The new target frame
88      */

89     public void setTarget(String JavaDoc target) {
90
91         this.target = target;
92
93     }
94
95
96     // ---------------------------------------------------- StateManager Methods
97

98
99     /**
100      * <p>Restore the state of this component.</p>
101      *
102      * @param context <code>FacesContext</code> for the current request
103      * @param state State object from which to restore our state
104      */

105     public void restoreState(FacesContext context, Object JavaDoc state) {
106
107         Object JavaDoc values[] = (Object JavaDoc[]) state;
108         super.restoreState(context, values[0]);
109         target = (String JavaDoc) values[1];
110
111     }
112
113
114     /**
115      * <p>Save the state of this component.</p>
116      *
117      * @param context <code>FacesContext</code> for the current request
118      */

119     public Object JavaDoc saveState(FacesContext context) {
120
121         Object JavaDoc values[] = new Object JavaDoc[2];
122         values[0] = super.saveState(context);
123         values[1] = target;
124         return values;
125
126     }
127
128
129 }
130
Popular Tags