KickJava   Java API By Example, From Geeks To Geeks.

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


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.BridgeFacesContext;
39 import com.icesoft.faces.context.effects.CurrentStyle;
40 import com.icesoft.faces.context.effects.Effect;
41 import com.icesoft.faces.context.effects.JavascriptContext;
42
43 import javax.faces.context.FacesContext;
44 import javax.faces.el.ValueBinding;
45
46 /**
47  * This is an extension of com.icesoft.faces.component.ext.HtmlInputText, which
48  * provides some additional behavior to this component such as: <ul> <li>default
49  * classes for enabled and disabled state</li> <li>provides full and partial
50  * submit mechanism</li> <li>changes the component's enabled and rendered state
51  * based on the authentication</li> <li>adds effects to the component</li>
52  * <li>allows to set the action and actionListener for this component</li> <ul>
53  */

54 public class HtmlInputSecret extends HtmlInputText {
55     public static final String JavaDoc COMPONENT_TYPE =
56             "com.icesoft.faces.HtmlInputSecret";
57     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Secret";
58     private static final boolean DEFAULT_VISIBLE = true;
59     private String JavaDoc styleClass = null;
60     private boolean redisplay = false;
61     private boolean redisplaySet = false;
62     private boolean focus = false;
63
64     private Effect onclickeffect;
65     private Effect ondblclickeffect;
66     private Effect onmousedowneffect;
67     private Effect onmouseupeffect;
68     private Effect onmousemoveeffect;
69     private Effect onmouseovereffect;
70     private Effect onmouseouteffect;
71     private Effect onchangeeffect;
72     private Effect onkeypresseffect;
73     private Effect onkeydowneffect;
74     private Effect onkeyupeffect;
75
76     private CurrentStyle currentStyle;
77
78     private Effect effect;
79     private Boolean JavaDoc visible = null;
80
81
82     public HtmlInputSecret() {
83         super();
84         setRendererType(RENDERER_TYPE);
85     }
86
87     /**
88      * This method is used to communicate a focus request from the application
89      * to the client browser.
90      */

91     public void requestFocus() {
92         ((BridgeFacesContext) FacesContext.getCurrentInstance())
93                 .setFocusId("null");
94         JavascriptContext.focus(FacesContext.getCurrentInstance(),
95                                 this.getClientId(
96                                         FacesContext.getCurrentInstance()));
97     }
98
99     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
100         if (s != null && s.indexOf("effect") != -1) {
101             // If this is an effect attribute make sure Ice Extras is included
102
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
103                                          getFacesContext());
104         }
105         super.setValueBinding(s, vb);
106     }
107
108     /**
109      * <p>Set the value of the <code>effect</code> property.</p>
110      */

111     public void setEffect(Effect effect) {
112         JavascriptContext
113                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
114         this.effect = effect;
115     }
116
117     /**
118      * <p>Return the value of the <code>effect</code> property.</p>
119      */

120     public Effect getEffect() {
121         if (effect != null) {
122             return effect;
123         }
124         ValueBinding vb = getValueBinding("effect");
125         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
126     }
127
128
129     /**
130      * <p>Set the value of the <code>visible</code> property.</p>
131      */

132     public void setVisible(boolean visible) {
133         this.visible = Boolean.valueOf(visible);
134     }
135
136     /**
137      * <p>Return the value of the <code>visible</code> property.</p>
138      */

139     public boolean getVisible() {
140         if (visible != null) {
141             return visible.booleanValue();
142         }
143         ValueBinding vb = getValueBinding("visible");
144         Boolean JavaDoc boolVal =
145                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
146         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
147     }
148
149
150     /**
151      * <p>Set the value of the <code>styleClass</code> property.</p>
152      */

153     public void setStyleClass(String JavaDoc styleClass) {
154         this.styleClass = styleClass;
155     }
156
157     /**
158      * <p>Return the value of the <code>styleClass</code> property.</p>
159      */

160     public String JavaDoc getStyleClass() {
161         return Util.getQualifiedStyleClass(this,
162                 styleClass,
163                 CSS_DEFAULT.INPUT_SECRET_DEFAULT_STYLE_CLASS,
164                 "styleClass",
165                 isDisabled());
166                                              
167     }
168
169     /**
170      * <p>Return the value of the <code>rendered</code> property.</p>
171      */

172     public boolean isRendered() {
173         if (!Util.isRenderedOnUserRole(this)) {
174             return false;
175         }
176         return super.isRendered();
177     }
178
179     /**
180      * <p>Set the value of the <code>redisplay</code> property.</p>
181      */

182     public void setRedisplay(boolean redisplay) {
183         this.redisplay = redisplay;
184     }
185
186     /**
187      * <p>Return the value of the <code>redisplay</code> property.</p>
188      */

189     public boolean isRedisplay() {
190         if (this.redisplaySet) {
191             return this.redisplay;
192         }
193         ValueBinding _vb = getValueBinding("redisplay");
194         if (_vb != null) {
195             Object JavaDoc _result = _vb.getValue(getFacesContext());
196             if (_result == null) {
197                 return false;
198             } else {
199                 return ((Boolean JavaDoc) _result).booleanValue();
200             }
201         } else {
202             return this.redisplay;
203         }
204     }
205
206     /**
207      * <p>Set the value of the <code>focus</code> property.</p>
208      */

209     public void setFocus(boolean focus) {
210         this.focus = focus;
211     }
212
213     /**
214      * <p>Return the value of the <code>focus</code> property.</p>
215      */

216     public boolean hasFocus() {
217         return focus;
218     }
219
220     /**
221      * <p>Return the value of the <code>onclickeffect</code> property.</p>
222      */

223     public Effect getOnclickeffect() {
224         if (onclickeffect != null) {
225             return onclickeffect;
226         }
227         ValueBinding vb = getValueBinding("onclickeffect");
228
229         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
230     }
231
232     /**
233      * <p>Set the value of the <code>onclickeffect</code> property.</p>
234      */

235     public void setOnclickeffect(Effect onclickeffect) {
236         JavascriptContext
237                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
238         this.onclickeffect = onclickeffect;
239     }
240
241     /**
242      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
243      */

244     public Effect getOndblclickeffect() {
245         if (ondblclickeffect != null) {
246             return ondblclickeffect;
247         }
248         ValueBinding vb = getValueBinding("ondblclickeffect");
249
250         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
251     }
252
253     /**
254      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
255      */

256     public void setOndblclickeffect(Effect ondblclickeffect) {
257         JavascriptContext
258                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
259         this.ondblclickeffect = ondblclickeffect;
260     }
261
262     /**
263      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
264      */

265     public Effect getOnmousedowneffect() {
266         if (onmousedowneffect != null) {
267             return onmousedowneffect;
268         }
269         ValueBinding vb = getValueBinding("onmousedowneffect");
270
271         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
272     }
273
274     /**
275      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
276      */

277     public void setOnmousedowneffect(Effect onmousedowneffect) {
278         JavascriptContext
279                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
280         this.onmousedowneffect = onmousedowneffect;
281     }
282
283     /**
284      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
285      */

286     public Effect getOnmouseupeffect() {
287         if (onmouseupeffect != null) {
288             return onmouseupeffect;
289         }
290         ValueBinding vb = getValueBinding("onmouseupeffect");
291
292         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
293     }
294
295     /**
296      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
297      */

298     public void setOnmouseupeffect(Effect onmouseupeffect) {
299         JavascriptContext
300                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
301         this.onmouseupeffect = onmouseupeffect;
302     }
303
304     /**
305      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
306      */

307     public Effect getOnmousemoveeffect() {
308         if (onmousemoveeffect != null) {
309             return onmousemoveeffect;
310         }
311         ValueBinding vb = getValueBinding("onmousemoveeffect");
312
313         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
314     }
315
316     /**
317      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
318      */

319     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
320         JavascriptContext
321                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
322         this.onmousemoveeffect = onmousemoveeffect;
323     }
324
325     /**
326      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
327      */

328     public Effect getOnmouseovereffect() {
329         if (onmouseovereffect != null) {
330             return onmouseovereffect;
331         }
332         ValueBinding vb = getValueBinding("onmouseovereffect");
333
334         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
335     }
336
337     /**
338      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
339      */

340     public void setOnmouseovereffect(Effect onmouseovereffect) {
341         JavascriptContext
342                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
343         this.onmouseovereffect = onmouseovereffect;
344     }
345
346     /**
347      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
348      */

349     public Effect getOnmouseouteffect() {
350         if (onmouseouteffect != null) {
351             return onmouseouteffect;
352         }
353         ValueBinding vb = getValueBinding("onmouseouteffect");
354
355         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
356     }
357
358     /**
359      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
360      */

361     public void setOnmouseouteffect(Effect onmouseouteffect) {
362         JavascriptContext
363                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
364         this.onmouseouteffect = onmouseouteffect;
365     }
366
367     /**
368      * <p>Return the value of the <code>onchangeeffect</code> property.</p>
369      */

370     public Effect getOnchangeeffect() {
371         if (onchangeeffect != null) {
372             return onchangeeffect;
373         }
374         ValueBinding vb = getValueBinding("onchangeeffect");
375
376         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
377     }
378
379     /**
380      * <p>Set the value of the <code>onchangeeffect</code> property.</p>
381      */

382     public void setOnchangeeffect(Effect onchangeeffect) {
383         JavascriptContext
384                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
385         this.onchangeeffect = onchangeeffect;
386     }
387
388     /**
389      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
390      */

391     public Effect getOnkeypresseffect() {
392         if (onkeypresseffect != null) {
393             return onkeypresseffect;
394         }
395         ValueBinding vb = getValueBinding("onkeypresseffect");
396
397         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
398     }
399
400     /**
401      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
402      */

403     public void setOnkeypresseffect(Effect onkeypresseffect) {
404         JavascriptContext
405                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
406         this.onkeypresseffect = onkeypresseffect;
407     }
408
409     /**
410      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
411      */

412     public Effect getOnkeydowneffect() {
413         if (onkeydowneffect != null) {
414             return onkeydowneffect;
415         }
416         ValueBinding vb = getValueBinding("onkeydowneffect");
417
418         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
419     }
420
421     /**
422      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
423      */

424     public void setOnkeydowneffect(Effect onkeydowneffect) {
425         JavascriptContext
426                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
427         this.onkeydowneffect = onkeydowneffect;
428     }
429
430     /**
431      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
432      */

433     public Effect getOnkeyupeffect() {
434         if (onkeyupeffect != null) {
435             return onkeyupeffect;
436         }
437         ValueBinding vb = getValueBinding("onkeyupeffect");
438
439         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
440     }
441
442     /**
443      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
444      */

445     public void setOnkeyupeffect(Effect onkeyupeffect) {
446         JavascriptContext
447                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
448         this.onkeyupeffect = onkeyupeffect;
449     }
450
451     /**
452      * <p>Return the value of the <code>currentStyle</code> property.</p>
453      */

454     public CurrentStyle getCurrentStyle() {
455         return currentStyle;
456     }
457
458     /**
459      * <p>Set the value of the <code>currentStyle</code> property.</p>
460      */

461     public void setCurrentStyle(CurrentStyle currentStyle) {
462         this.currentStyle = currentStyle;
463     }
464
465     private String JavaDoc autocomplete;
466
467     /**
468      * <p>Set the value of the <code>autocomplete</code> property.</p>
469      */

470     public void setAutocomplete(String JavaDoc autocomplete) {
471         this.autocomplete = autocomplete;
472     }
473
474     /**
475      * <p>Return the value of the <code>autocomplete</code> property.</p>
476      */

477     public String JavaDoc getAutocomplete() {
478         if (autocomplete != null) {
479             return autocomplete;
480         }
481         ValueBinding vb = getValueBinding("autocomplete");
482         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
483     }
484
485
486     /**
487      * <p>Gets the state of the instance as a <code>Serializable</code>
488      * Object.</p>
489      */

490     public Object JavaDoc saveState(FacesContext context) {
491         Object JavaDoc values[] = new Object JavaDoc[21];
492         values[0] = super.saveState(context);
493         values[1] = onkeyupeffect;
494         values[2] = styleClass;
495         values[3] = redisplay ? Boolean.TRUE : Boolean.FALSE;
496         values[4] = redisplaySet ? Boolean.TRUE : Boolean.FALSE;
497         values[5] = onclickeffect;
498         values[6] = ondblclickeffect;
499         values[7] = onmousedowneffect;
500         values[8] = onmouseupeffect;
501         values[9] = onmousemoveeffect;
502         values[10] = onmouseovereffect;
503         values[11] = onmouseouteffect;
504         values[12] = onchangeeffect;
505         values[15] = onkeypresseffect;
506         values[16] = onkeydowneffect;
507         values[17] = currentStyle;
508         values[18] = effect;
509         values[19] = visible;
510         values[20] = autocomplete;
511         return ((Object JavaDoc) (values));
512     }
513
514     /**
515      * <p>Perform any processing required to restore the state from the entries
516      * in the state Object.</p>
517      */

518     public void restoreState(FacesContext context, Object JavaDoc state) {
519         Object JavaDoc values[] = (Object JavaDoc[]) state;
520         super.restoreState(context, values[0]);
521         onkeyupeffect = (Effect) values[1];
522         styleClass = (String JavaDoc) values[2];
523         redisplay = ((Boolean JavaDoc) values[3]).booleanValue();
524         redisplaySet = ((Boolean JavaDoc) values[3]).booleanValue();
525         onclickeffect = (Effect) values[5];
526         ondblclickeffect = (Effect) values[6];
527         onmousedowneffect = (Effect) values[7];
528         onmouseupeffect = (Effect) values[8];
529         onmousemoveeffect = (Effect) values[9];
530         onmouseovereffect = (Effect) values[10];
531         onmouseouteffect = (Effect) values[11];
532         onchangeeffect = (Effect) values[12];
533         onkeypresseffect = (Effect) values[15];
534         onkeydowneffect = (Effect) values[16];
535         currentStyle = (CurrentStyle) values[17];
536         effect = (Effect) values[18];
537         visible = (Boolean JavaDoc) values[19];
538         autocomplete = (String JavaDoc) values[20];
539     }
540 }
541
Popular Tags