KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > ext > HtmlMessages


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.ext;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38 import com.icesoft.faces.context.effects.CurrentStyle;
39 import com.icesoft.faces.context.effects.Effect;
40 import com.icesoft.faces.context.effects.JavascriptContext;
41
42 import javax.faces.context.FacesContext;
43 import javax.faces.el.ValueBinding;
44
45
46 /**
47  * This is an extension of javax.faces.component.html.HtmlMessages, which
48  * provides some additional behavior to this component such as: <ul> <li>changes
49  * the component's rendered state based on the authentication</li> <li>adds
50  * effects to the component</li> <ul>
51  */

52 public class HtmlMessages extends javax.faces.component.html.HtmlMessages {
53     public static final String JavaDoc COMPONENT_TYPE =
54             "com.icesoft.faces.HtmlMessages";
55     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Messages";
56     private static final boolean DEFAULT_VISIBLE = true;
57     private String JavaDoc renderedOnUserRole = null;
58     private Effect effect;
59     private Boolean JavaDoc visible = null;
60     private String JavaDoc errorClass = null;
61     private String JavaDoc fatalClass = null;
62     private String JavaDoc infoClass = null;
63     private String JavaDoc warnClass = null;
64     private String JavaDoc styleClass = null;
65     private CurrentStyle currentStyle;
66
67     public HtmlMessages() {
68         super();
69         setRendererType(RENDERER_TYPE);
70     }
71
72     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
73         if (s != null && s.indexOf("effect") != -1) {
74             // If this is an effect attribute make sure Ice Extras is included
75
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
76                                          getFacesContext());
77         }
78         super.setValueBinding(s, vb);
79     }
80
81     /**
82      * <p>Set the value of the <code>effect</code> property.</p>
83      */

84     public void setEffect(Effect effect) {
85         this.effect = effect;
86         JavascriptContext
87                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
88     }
89
90     /**
91      * <p>Return the value of the <code>effect</code> property.</p>
92      */

93     public Effect getEffect() {
94         if (effect != null) {
95             return effect;
96         }
97         ValueBinding vb = getValueBinding("effect");
98         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
99     }
100
101     /**
102      * <p>Set the value of the <code>visible</code> property.</p>
103      */

104     public void setVisible(boolean visible) {
105         this.visible = Boolean.valueOf(visible);
106     }
107
108     /**
109      * <p>Return the value of the <code>visible</code> property.</p>
110      */

111     public boolean getVisible() {
112         if (visible != null) {
113             return visible.booleanValue();
114         }
115         ValueBinding vb = getValueBinding("visible");
116         Boolean JavaDoc boolVal =
117                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
118         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
119     }
120
121     /**
122      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
123      */

124     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
125         this.renderedOnUserRole = renderedOnUserRole;
126     }
127
128     /**
129      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
130      */

131     public String JavaDoc getRenderedOnUserRole() {
132         if (renderedOnUserRole != null) {
133             return renderedOnUserRole;
134         }
135         ValueBinding vb = getValueBinding("renderedOnUserRole");
136         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
137     }
138
139     /**
140      * <p>Return the value of the <code>rendered</code> property.</p>
141      */

142     public boolean isRendered() {
143         if (!Util.isRenderedOnUserRole(this)) {
144             return false;
145         }
146         return super.isRendered();
147     }
148
149     /**
150      * <p>Return the value of the <code>currentStyle</code> property.</p>
151      */

152     public CurrentStyle getCurrentStyle() {
153         return currentStyle;
154     }
155
156     /**
157      * <p>Set the value of the <code>currentStyle</code> property.</p>
158      */

159     public void setCurrentStyle(CurrentStyle currentStyle) {
160         this.currentStyle = currentStyle;
161     }
162
163     /**
164      * <p>Gets the state of the instance as a <code>Serializable</code>
165      * Object.</p>
166      */

167     public Object JavaDoc saveState(FacesContext context) {
168         Object JavaDoc values[] = new Object JavaDoc[5];
169         values[0] = super.saveState(context);
170         values[1] = renderedOnUserRole;
171         values[2] = effect;
172         values[3] = currentStyle;
173         values[4] = visible;
174         return ((Object JavaDoc) (values));
175     }
176
177     /**
178      * <p>Perform any processing required to restore the state from the entries
179      * in the state Object.</p>
180      */

181     public void restoreState(FacesContext context, Object JavaDoc state) {
182         Object JavaDoc values[] = (Object JavaDoc[]) state;
183         super.restoreState(context, values[0]);
184         renderedOnUserRole = (String JavaDoc) values[1];
185         effect = (Effect) values[2];
186         currentStyle = (CurrentStyle) values[3];
187         visible = (Boolean JavaDoc) values[4];
188     }
189
190     /**
191      * <p>Set the value of the <code>styleClass</code> property.</p>
192      */

193     public void setStyleClass(String JavaDoc styleClass) {
194         this.styleClass = styleClass;
195     }
196
197     /**
198      * <p>Return the value of the <code>styleClass</code> property.</p>
199      */

200     public String JavaDoc getStyleClass() {
201         return Util.getQualifiedStyleClass(this,
202                 styleClass,
203                 CSS_DEFAULT.MESSAGES_STYLE_CLASS,
204                 "styleClass");
205     }
206
207
208     /**
209      * <p>Set the value of the <code>errorClass</code> property.</p>
210      */

211     public void setErrorClass(String JavaDoc errorClass) {
212         this.errorClass = errorClass;
213     }
214
215     /**
216      * <p>Return the value of the <code>errorClass</code> property.</p>
217      */

218     public String JavaDoc getErrorClass() {
219         return Util.getQualifiedStyleClass(this,
220                 errorClass,
221                 CSS_DEFAULT.ERROR_STYLE_CLASS,
222                 "errorClass");
223     }
224
225
226     /**
227      * <p>Set the value of the <code>fataClass</code> property.</p>
228      */

229     public void setFatalClass(String JavaDoc fatalClass) {
230         this.fatalClass = fatalClass;
231     }
232
233     /**
234      * <p>Return the value of the <code>fataClass</code> property.</p>
235      */

236     public String JavaDoc getFatalClass() {
237         return Util.getQualifiedStyleClass(this,
238                 fatalClass,
239                 CSS_DEFAULT.FATAL_STYLE_CLASS,
240                 "fatalClass");
241     }
242
243
244     /**
245      * <p>Set the value of the <code>infoClass</code> property.</p>
246      */

247     public void setInfoClass(String JavaDoc infoClass) {
248         this.infoClass = infoClass;
249     }
250
251     /**
252      * <p>Return the value of the <code>infoClass</code> property.</p>
253      */

254     public String JavaDoc getInfoClass() {
255         return Util.getQualifiedStyleClass(this,
256                 infoClass,
257                 CSS_DEFAULT.INFO_STYLE_CLASS,
258                 "infoClass");
259     }
260
261     /**
262      * <p>Set the value of the <code>warnClass</code> property.</p>
263      */

264     public void setWarnClass(String JavaDoc warnClass) {
265         this.warnClass = warnClass;
266     }
267
268     /**
269      * <p>Return the value of the <code>warnClass</code> property.</p>
270      */

271     public String JavaDoc getWarnClass() {
272         return Util.getQualifiedStyleClass(this,
273                 warnClass,
274                 CSS_DEFAULT.WARN_STYLE_CLASS,
275                 "warnClass");
276     }
277 }
278
Popular Tags