KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This is an extension of javax.faces.component.html.HtmlMessage, which
47  * provides some additional behavior to this component such as: <ul> <li>changes
48  * the component's rendered state based on the authentication</li> <li>adds
49  * effects to the component</li> <ul>
50  */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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