KickJava   Java API By Example, From Geeks To Geeks.

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


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:write&gt;</code> tag.</p>
28  */

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

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

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

49
50     /**
51      * <p>Flag indicating whether output should be filtered.</p>
52      */

53     private boolean filter = true;
54     private boolean filterSet = false;
55
56
57     /**
58      * <p>CSS style(s) to be rendered for this component.</p>
59      */

60     private String JavaDoc style = null;
61
62
63     /**
64      * <p>CSS style class(es) to be rendered for this component.</p>
65      */

66     private String JavaDoc styleClass = null;
67
68
69     // ---------------------------------------------------- Component Properties
70

71
72     /**
73      * <p>Return the component family to which this component belongs.</p>
74      */

75     public String JavaDoc getFamily() {
76
77         return "org.apache.struts.faces.Write";
78
79     }
80
81
82     /**
83      * <p>Return a flag indicating whether filtering should take place.</p>
84      */

85     public boolean isFilter() {
86
87         if (filterSet) {
88             return filter;
89         }
90         ValueBinding vb = getValueBinding("filter");
91         if (vb != null) {
92             Boolean JavaDoc value = (Boolean JavaDoc) vb.getValue(getFacesContext());
93             if (null == value) {
94                 return filter;
95             }
96             return value.booleanValue();
97         } else {
98             return filter;
99         }
100
101     }
102
103
104     /**
105      * <p>Set the flag indicating that the output value should be filtered.</p>
106      *
107      * @param filter The new filter flag
108      */

109     public void setFilter(boolean filter) {
110
111         this.filter = filter;
112         this.filterSet = true;
113
114     }
115
116
117     /**
118      * <p>Return the CSS style(s) to be rendered for this component.</p>
119      */

120     public String JavaDoc getStyle() {
121
122         ValueBinding vb = getValueBinding("style");
123         if (vb != null) {
124             return (String JavaDoc) vb.getValue(getFacesContext());
125         } else {
126             return style;
127         }
128
129     }
130
131
132     /**
133      * <p>Set the CSS style(s) to be rendered for this component.</p>
134      *
135      * @param style The new CSS style(s)
136      */

137     public void setStyle(String JavaDoc style) {
138
139         this.style = style;
140
141     }
142
143
144     /**
145      * <p>Return the CSS style class(es) to be rendered for this component.</p>
146      */

147     public String JavaDoc getStyleClass() {
148
149         ValueBinding vb = getValueBinding("styleClass");
150         if (vb != null) {
151             return (String JavaDoc) vb.getValue(getFacesContext());
152         } else {
153             return styleClass;
154         }
155
156     }
157
158
159     /**
160      * <p>Set the CSS style class(es) to be rendered for this component.</p>
161      *
162      * @param styleClass The new CSS style class(es)
163      */

164     public void setStyleClass(String JavaDoc styleClass) {
165
166         this.styleClass = styleClass;
167
168     }
169
170
171     // ---------------------------------------------------- StateManager Methods
172

173
174     /**
175      * <p>Restore the state of this component.</p>
176      *
177      * @param context <code>FacesContext</code> for the current request
178      * @param state State object from which to restore our state
179      */

180     public void restoreState(FacesContext context, Object JavaDoc state) {
181
182         Object JavaDoc values[] = (Object JavaDoc[]) state;
183         super.restoreState(context, values[0]);
184         filter = ((Boolean JavaDoc) values[1]).booleanValue();
185         filterSet = ((Boolean JavaDoc) values[2]).booleanValue();
186         style = (String JavaDoc) values[3];
187         styleClass = (String JavaDoc) values[4];
188
189     }
190
191
192     /**
193      * <p>Save the state of this component.</p>
194      *
195      * @param context <code>FacesContext</code> for the current request
196      */

197     public Object JavaDoc saveState(FacesContext context) {
198
199         Object JavaDoc values[] = new Object JavaDoc[5];
200         values[0] = super.saveState(context);
201         values[1] = filter ? Boolean.TRUE : Boolean.FALSE;
202         values[2] = filterSet ? Boolean.TRUE : Boolean.FALSE;
203         values[3] = style;
204         values[4] = styleClass;
205         return values;
206
207     }
208
209
210 }
211
Popular Tags