KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

114     public void setVisible(boolean visible) {
115         this.visible = Boolean.valueOf(visible);
116     }
117
118     /**
119      * <p>Return the value of the <code>visible</code> property.</p>
120      */

121     public boolean getVisible() {
122         if (visible != null) {
123             return visible.booleanValue();
124         }
125         ValueBinding vb = getValueBinding("visible");
126         Boolean JavaDoc boolVal =
127                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
128         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
129     }
130
131     /**
132      * <p>Set the value of the <code>effect</code> property.</p>
133      */

134     public void setEffect(Effect effect) {
135         this.effect = effect;
136         JavascriptContext
137                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
138     }
139
140     /**
141      * <p>Return the value of the <code>effect</code> property.</p>
142      */

143     public Effect getEffect() {
144         if (effect != null) {
145             return effect;
146         }
147         ValueBinding vb = getValueBinding("effect");
148         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
149     }
150
151     /**
152      * <p>Set the value of the <code>partialSubmit</code> property.</p>
153      */

154     public void setPartialSubmit(boolean partialSubmit) {
155         this.partialSubmit = Boolean.valueOf(partialSubmit);
156     }
157
158     /**
159      * <p>Return the value of the <code>partialSubmit</code> property.</p>
160      */

161     public boolean getPartialSubmit() {
162         if (partialSubmit != null) {
163             return partialSubmit.booleanValue();
164         }
165         ValueBinding vb = getValueBinding("partialSubmit");
166         Boolean JavaDoc boolVal =
167                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
168         return boolVal != null ? boolVal.booleanValue() :
169                Util.isParentPartialSubmit(this);
170     }
171
172     /**
173      * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
174      */

175     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
176         this.enabledOnUserRole = enabledOnUserRole;
177     }
178
179     /**
180      * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
181      */

182     public String JavaDoc getEnabledOnUserRole() {
183         if (enabledOnUserRole != null) {
184             return enabledOnUserRole;
185         }
186         ValueBinding vb = getValueBinding("enabledOnUserRole");
187         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
188     }
189
190     /**
191      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
192      */

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

200     public String JavaDoc getRenderedOnUserRole() {
201         if (renderedOnUserRole != null) {
202             return renderedOnUserRole;
203         }
204         ValueBinding vb = getValueBinding("renderedOnUserRole");
205         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
206     }
207
208     /**
209      * <p>Set the value of the <code>styleClass</code> property.</p>
210      */

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

218     public String JavaDoc getStyleClass() {
219         return Util.getQualifiedStyleClass(this,
220                 styleClass,
221                 CSS_DEFAULT.SELECT_ONE_LISTBOX_DEFAULT_STYLE_CLASS,
222                 "styleClass",
223                 isDisabled());
224     }
225
226     /**
227      * <p>Return the value of the <code>rendered</code> property.</p>
228      */

229     public boolean isRendered() {
230         if (!Util.isRenderedOnUserRole(this)) {
231             return false;
232         }
233         return super.isRendered();
234     }
235
236     /**
237      * <p>Return the value of the <code>disabled</code> property.</p>
238      */

239     public boolean isDisabled() {
240         if (!Util.isEnabledOnUserRole(this)) {
241             return true;
242         } else {
243             return super.isDisabled();
244         }
245     }
246
247     /**
248      * <p>Return the value of the <code>onchangeeffect</code> property.</p>
249      */

250     public Effect getOnchangeeffect() {
251         if (onchangeeffect != null) {
252             return onchangeeffect;
253         }
254         ValueBinding vb = getValueBinding("onchangeeffect");
255
256         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
257     }
258
259     /**
260      * <p>Set the value of the <code>onchangeeffect</code> property.</p>
261      */

262     public void setOnchangeeffect(Effect onchangeeffect) {
263         this.onchangeeffect = onchangeeffect;
264         JavascriptContext
265                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
266     }
267
268     /**
269      * <p>Return the value of the <code>currentStyle</code> property.</p>
270      */

271     public CurrentStyle getCurrentStyle() {
272         return currentStyle;
273     }
274
275     /**
276      * <p>Set the value of the <code>currentStyle</code> property.</p>
277      */

278     public void setCurrentStyle(CurrentStyle currentStyle) {
279         this.currentStyle = currentStyle;
280     }
281
282
283
284
285
286
287     /**
288      * <p>Set the value of the <code>onclickeffect</code> property.</p>
289      */

290     public void setOnclickeffect(Effect onclickeffect) {
291         this.onclickeffect = onclickeffect;
292         JavascriptContext
293                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
294     }
295
296     /**
297      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
298      */

299     public Effect getOndblclickeffect() {
300         if (ondblclickeffect != null) {
301             return ondblclickeffect;
302         }
303         ValueBinding vb = getValueBinding("ondblclickeffect");
304
305         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
306     }
307
308     /**
309      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
310      */

311     public void setOndblclickeffect(Effect ondblclickeffect) {
312         this.ondblclickeffect = ondblclickeffect;
313         JavascriptContext
314                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
315     }
316
317     /**
318      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
319      */

320     public Effect getOnmousedowneffect() {
321         if (onmousedowneffect != null) {
322             return onmousedowneffect;
323         }
324         ValueBinding vb = getValueBinding("onmousedowneffect");
325
326         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
327     }
328
329     /**
330      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
331      */

332     public void setOnmousedowneffect(Effect onmousedowneffect) {
333         this.onmousedowneffect = onmousedowneffect;
334         JavascriptContext
335                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
336     }
337
338     /**
339      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
340      */

341     public Effect getOnmouseupeffect() {
342         if (onmouseupeffect != null) {
343             return onmouseupeffect;
344         }
345         ValueBinding vb = getValueBinding("onmouseupeffect");
346
347         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
348     }
349
350     /**
351      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
352      */

353     public void setOnmouseupeffect(Effect onmouseupeffect) {
354         this.onmouseupeffect = onmouseupeffect;
355         JavascriptContext
356                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
357     }
358
359     /**
360      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
361      */

362     public Effect getOnmousemoveeffect() {
363         if (onmousemoveeffect != null) {
364             return onmousemoveeffect;
365         }
366         ValueBinding vb = getValueBinding("onmousemoveeffect");
367
368         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
369     }
370
371     /**
372      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
373      */

374     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
375         this.onmousemoveeffect = onmousemoveeffect;
376         JavascriptContext
377                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
378     }
379
380     /**
381      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
382      */

383     public Effect getOnmouseovereffect() {
384         if (onmouseovereffect != null) {
385             return onmouseovereffect;
386         }
387         ValueBinding vb = getValueBinding("onmouseovereffect");
388
389         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
390     }
391
392     /**
393      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
394      */

395     public void setOnmouseovereffect(Effect onmouseovereffect) {
396         this.onmouseovereffect = onmouseovereffect;
397         JavascriptContext
398                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
399     }
400
401     /**
402      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
403      */

404     public Effect getOnmouseouteffect() {
405         if (onmouseouteffect != null) {
406             return onmouseouteffect;
407         }
408         ValueBinding vb = getValueBinding("onmouseouteffect");
409
410         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
411     }
412
413     /**
414      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
415      */

416     public void setOnmouseouteffect(Effect onmouseouteffect) {
417         this.onmouseouteffect = onmouseouteffect;
418         JavascriptContext
419                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
420     }
421
422
423     /**
424      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
425      */

426     public Effect getOnkeypresseffect() {
427         if (onkeypresseffect != null) {
428             return onkeypresseffect;
429         }
430         ValueBinding vb = getValueBinding("onkeypresseffect");
431
432         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
433     }
434
435     /**
436      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
437      */

438     public void setOnkeypresseffect(Effect onkeypresseffect) {
439         this.onkeypresseffect = onkeypresseffect;
440         JavascriptContext
441                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
442     }
443
444
445
446
447
448
449
450
451
452     /**
453      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
454      */

455     public Effect getOnkeydowneffect() {
456         if (onkeydowneffect != null) {
457             return onkeydowneffect;
458         }
459         ValueBinding vb = getValueBinding("onkeydowneffect");
460
461         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
462     }
463
464     /**
465      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
466      */

467     public void setOnkeydowneffect(Effect onkeydowneffect) {
468         this.onkeydowneffect = onkeydowneffect;
469         JavascriptContext
470                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
471     }
472
473     /**
474      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
475      */

476     public Effect getOnkeyupeffect() {
477         if (onkeyupeffect != null) {
478             return onkeyupeffect;
479         }
480         ValueBinding vb = getValueBinding("onkeyupeffect");
481
482         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
483     }
484
485     /**
486      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
487      */

488     public void setOnkeyupeffect(Effect onkeyupeffect) {
489         this.onkeyupeffect = onkeyupeffect;
490         JavascriptContext
491                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
492     }
493
494     /**
495      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
496      */

497     public Effect getOnclickeffect() {
498         if (onclickeffect != null) {
499             return onclickeffect;
500         }
501         ValueBinding vb = getValueBinding("onclickeffect");
502
503         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
504     }
505
506
507     private String JavaDoc autocomplete;
508
509     /**
510      * <p>Set the value of the <code>autocomplete</code> property.</p>
511      */

512     public void setAutocomplete(String JavaDoc autocomplete) {
513         this.autocomplete = autocomplete;
514     }
515
516     /**
517      * <p>Return the value of the <code>autocomplete</code> property.</p>
518      */

519     public String JavaDoc getAutocomplete() {
520         if (autocomplete != null) {
521             return autocomplete;
522         }
523         ValueBinding vb = getValueBinding("autocomplete");
524         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
525     }
526
527
528     /**
529      * <p>Gets the state of the instance as a <code>Serializable</code>
530      * Object.</p>
531      */

532     public Object JavaDoc saveState(FacesContext context) {
533         Object JavaDoc values[] = new Object JavaDoc[21];
534         values[0] = super.saveState(context);
535         values[1] = partialSubmit;
536         values[2] = enabledOnUserRole;
537         values[3] = renderedOnUserRole;
538         values[4] = styleClass;
539         values[5] = effect;
540         values[13] = onchangeeffect;
541         values[19] = currentStyle;
542         values[20] = visible;
543         return ((Object JavaDoc) (values));
544     }
545
546     /**
547      * <p>Perform any processing required to restore the state from the entries
548      * in the state Object.</p>
549      */

550     public void restoreState(FacesContext context, Object JavaDoc state) {
551         Object JavaDoc values[] = (Object JavaDoc[]) state;
552         super.restoreState(context, values[0]);
553         partialSubmit = (Boolean JavaDoc) values[1];
554         enabledOnUserRole = (String JavaDoc) values[2];
555         renderedOnUserRole = (String JavaDoc) values[3];
556         styleClass = (String JavaDoc) values[4];
557         effect = (Effect) values[5];
558         onchangeeffect = (Effect) values[13];
559         currentStyle = (CurrentStyle) values[19];
560         visible = (Boolean JavaDoc) values[20];
561     }
562 }
563
564
565
Popular Tags