KickJava   Java API By Example, From Geeks To Geeks.

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


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.HtmlSelectOneRadio, which
50  * provides some additional behavior to this component such as: <ul> <li>default
51  * classes for enabled and disabled state</li> <li>provides partial submit
52  * mechanism</li> <li>changes the component's enabled and rendered state based
53  * on the authentication</li> <li>adds effects to the component</li> <ul>
54  */

55 public class HtmlSelectOneRadio
56         extends javax.faces.component.html.HtmlSelectOneRadio
57         implements IceExtended {
58
59     public static final String JavaDoc COMPONENT_TYPE =
60             "com.icesoft.faces.HtmlSelectOneRadio";
61     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Radio";
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
72     private Effect onclickeffect;
73     private Effect ondblclickeffect;
74     private Effect onmousedowneffect;
75     private Effect onmouseupeffect;
76     private Effect onmousemoveeffect;
77     private Effect onmouseovereffect;
78     private Effect onmouseouteffect;
79     private Effect onchangeeffect;
80     private Effect onkeypresseffect;
81     private Effect onkeydowneffect;
82     private Effect onkeyupeffect;
83
84     public HtmlSelectOneRadio() {
85         super();
86         setRendererType(RENDERER_TYPE);
87     }
88
89     /**
90      * This method is used to communicate a focus request from the application
91      * to the client browser.
92      */

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

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

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

134     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
135         this.enabledOnUserRole = enabledOnUserRole;
136     }
137
138     /**
139      * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
140      */

141     public String JavaDoc getEnabledOnUserRole() {
142         if (enabledOnUserRole != null) {
143             return enabledOnUserRole;
144         }
145         ValueBinding vb = getValueBinding("enabledOnUserRole");
146         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
147     }
148
149     /**
150      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
151      */

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

159     public String JavaDoc getRenderedOnUserRole() {
160         if (renderedOnUserRole != null) {
161             return renderedOnUserRole;
162         }
163         ValueBinding vb = getValueBinding("renderedOnUserRole");
164         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
165     }
166
167     /**
168      * <p>Set the value of the <code>styleClass</code> property.</p>
169      */

170     public void setStyleClass(String JavaDoc styleClass) {
171         this.styleClass = styleClass;
172     }
173
174     /**
175      * <p>Return the value of the <code>styleClass</code> property.</p>
176      */

177     public String JavaDoc getStyleClass() {
178         return Util.getQualifiedStyleClass(this,
179                 styleClass,
180                 CSS_DEFAULT.SELECT_ONE_RADIO_DEFAULT_STYLE_CLASS,
181                 "styleClass",
182                 isDisabled());
183     }
184
185     /**
186      * <p>Return the value of the <code>rendered</code> property.</p>
187      */

188     public boolean isRendered() {
189         if (!Util.isRenderedOnUserRole(this)) {
190             return false;
191         }
192         return super.isRendered();
193     }
194
195     /**
196      * <p>Return the value of the <code>disabled</code> property.</p>
197      */

198     public boolean isDisabled() {
199         if (!Util.isEnabledOnUserRole(this)) {
200             return true;
201         } else {
202             return super.isDisabled();
203         }
204     }
205
206     /**
207      * <p>Return the value of the <code>onclickeffect</code> property.</p>
208      */

209     public Effect getOnclickeffect() {
210         if (onclickeffect != null) {
211             return onclickeffect;
212         }
213         ValueBinding vb = getValueBinding("onclickeffect");
214
215         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
216     }
217
218     /**
219      * <p>Set the value of the <code>onclickeffect</code> property.</p>
220      */

221     public void setOnclickeffect(Effect onclickeffect) {
222         this.onclickeffect = onclickeffect;
223         JavascriptContext
224                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
225     }
226
227     /**
228      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
229      */

230     public Effect getOndblclickeffect() {
231         if (ondblclickeffect != null) {
232             return ondblclickeffect;
233         }
234         ValueBinding vb = getValueBinding("ondblclickeffect");
235
236         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
237     }
238
239     /**
240      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
241      */

242     public void setOndblclickeffect(Effect ondblclickeffect) {
243         this.ondblclickeffect = ondblclickeffect;
244         JavascriptContext
245                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
246     }
247
248     /**
249      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
250      */

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

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

272     public Effect getOnmouseupeffect() {
273         if (onmouseupeffect != null) {
274             return onmouseupeffect;
275         }
276         ValueBinding vb = getValueBinding("onmouseupeffect");
277
278         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
279     }
280
281     /**
282      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
283      */

284     public void setOnmouseupeffect(Effect onmouseupeffect) {
285         this.onmouseupeffect = onmouseupeffect;
286         JavascriptContext
287                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
288     }
289
290     /**
291      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
292      */

293     public Effect getOnmousemoveeffect() {
294         if (onmousemoveeffect != null) {
295             return onmousemoveeffect;
296         }
297         ValueBinding vb = getValueBinding("onmousemoveeffect");
298
299         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
300     }
301
302     /**
303      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
304      */

305     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
306         this.onmousemoveeffect = onmousemoveeffect;
307         JavascriptContext
308                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
309     }
310
311     /**
312      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
313      */

314     public Effect getOnmouseovereffect() {
315         if (onmouseovereffect != null) {
316             return onmouseovereffect;
317         }
318         ValueBinding vb = getValueBinding("onmouseovereffect");
319
320         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
321     }
322
323     /**
324      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
325      */

326     public void setOnmouseovereffect(Effect onmouseovereffect) {
327         this.onmouseovereffect = onmouseovereffect;
328         JavascriptContext
329                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
330     }
331
332     /**
333      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
334      */

335     public Effect getOnmouseouteffect() {
336         if (onmouseouteffect != null) {
337             return onmouseouteffect;
338         }
339         ValueBinding vb = getValueBinding("onmouseouteffect");
340
341         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
342     }
343
344     /**
345      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
346      */

347     public void setOnmouseouteffect(Effect onmouseouteffect) {
348         this.onmouseouteffect = onmouseouteffect;
349         JavascriptContext
350                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
351     }
352
353     /**
354      * <p>Return the value of the <code>onchangeeffect</code> property.</p>
355      */

356     public Effect getOnchangeeffect() {
357         if (onchangeeffect != null) {
358             return onchangeeffect;
359         }
360         ValueBinding vb = getValueBinding("onchangeeffect");
361
362         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
363     }
364
365     /**
366      * <p>Set the value of the <code>onchangeeffect</code> property.</p>
367      */

368     public void setOnchangeeffect(Effect onchangeeffect) {
369         this.onchangeeffect = onchangeeffect;
370         JavascriptContext
371                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
372     }
373
374
375     /**
376      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
377      */

378     public Effect getOnkeypresseffect() {
379         if (onkeypresseffect != null) {
380             return onkeypresseffect;
381         }
382         ValueBinding vb = getValueBinding("onkeypresseffect");
383
384         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
385     }
386
387     /**
388      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
389      */

390     public void setOnkeypresseffect(Effect onkeypresseffect) {
391         this.onkeypresseffect = onkeypresseffect;
392         JavascriptContext
393                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
394     }
395
396     /**
397      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
398      */

399     public Effect getOnkeydowneffect() {
400         if (onkeydowneffect != null) {
401             return onkeydowneffect;
402         }
403         ValueBinding vb = getValueBinding("onkeydowneffect");
404
405         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
406     }
407
408     /**
409      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
410      */

411     public void setOnkeydowneffect(Effect onkeydowneffect) {
412         this.onkeydowneffect = onkeydowneffect;
413         JavascriptContext
414                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
415     }
416
417     /**
418      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
419      */

420     public Effect getOnkeyupeffect() {
421         if (onkeyupeffect != null) {
422             return onkeyupeffect;
423         }
424         ValueBinding vb = getValueBinding("onkeyupeffect");
425
426         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
427     }
428
429     /**
430      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
431      */

432     public void setOnkeyupeffect(Effect onkeyupeffect) {
433         this.onkeyupeffect = onkeyupeffect;
434         JavascriptContext
435                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
436     }
437
438     /**
439      * <p>Return the value of the <code>currentStyle</code> property.</p>
440      */

441     public CurrentStyle getCurrentStyle() {
442         return currentStyle;
443     }
444
445     /**
446      * <p>Set the value of the <code>currentStyle</code> property.</p>
447      */

448     public void setCurrentStyle(CurrentStyle currentStyle) {
449         this.currentStyle = currentStyle;
450     }
451
452     /**
453      * <p>Set the value of the <code>visible</code> property.</p>
454      */

455     public void setVisible(boolean visible) {
456         this.visible = Boolean.valueOf(visible);
457     }
458
459     /**
460      * <p>Return the value of the <code>visible</code> property.</p>
461      */

462     public boolean getVisible() {
463         if (visible != null) {
464             return visible.booleanValue();
465         }
466         ValueBinding vb = getValueBinding("visible");
467         Boolean JavaDoc boolVal =
468                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
469         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
470     }
471
472     private String JavaDoc autocomplete;
473
474     /**
475      * <p>Set the value of the <code>autocomplete</code> property.</p>
476      */

477     public void setAutocomplete(String JavaDoc autocomplete) {
478         this.autocomplete = autocomplete;
479     }
480
481     /**
482      * <p>Return the value of the <code>autocomplete</code> property.</p>
483      */

484     public String JavaDoc getAutocomplete() {
485         if (autocomplete != null) {
486             return autocomplete;
487         }
488         ValueBinding vb = getValueBinding("autocomplete");
489         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
490     }
491
492     /**
493      * <p>Set the value of the <code>effect</code> property.</p>
494      */

495     public void setEffect(Effect effect) {
496         this.effect = effect;
497         JavascriptContext
498                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
499     }
500
501     /**
502      * <p>Return the value of the <code>effect</code> property.</p>
503      */

504     public Effect getEffect() {
505         if (effect != null) {
506             return effect;
507         }
508         ValueBinding vb = getValueBinding("effect");
509         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
510     }
511
512     /**
513      * <p>Gets the state of the instance as a <code>Serializable</code>
514      * Object.</p>
515      */

516     public Object JavaDoc saveState(FacesContext context) {
517         Object JavaDoc values[] = new Object JavaDoc[22];
518         values[0] = super.saveState(context);
519         values[1] = partialSubmit;
520         values[2] = enabledOnUserRole;
521         values[3] = renderedOnUserRole;
522         values[4] = styleClass;
523         values[5] = effect;
524         values[6] = onclickeffect;
525         values[7] = ondblclickeffect;
526         values[8] = onmousedowneffect;
527         values[9] = onmouseupeffect;
528         values[10] = onmousemoveeffect;
529         values[11] = onmouseovereffect;
530         values[12] = onmouseouteffect;
531         values[13] = onchangeeffect;
532         values[16] = onkeypresseffect;
533         values[17] = onkeydowneffect;
534         values[18] = onkeyupeffect;
535         values[19] = currentStyle;
536         values[20] = visible;
537         values[21] = autocomplete;
538         return ((Object JavaDoc) (values));
539     }
540
541     /**
542      * <p>Perform any processing required to restore the state from the entries
543      * in the state Object.</p>
544      */

545     public void restoreState(FacesContext context, Object JavaDoc state) {
546         Object JavaDoc values[] = (Object JavaDoc[]) state;
547         super.restoreState(context, values[0]);
548         partialSubmit = (Boolean JavaDoc) values[1];
549         enabledOnUserRole = (String JavaDoc) values[2];
550         renderedOnUserRole = (String JavaDoc) values[3];
551         styleClass = (String JavaDoc) values[4];
552         effect = (Effect) values[5];
553         onclickeffect = (Effect) values[6];
554         ondblclickeffect = (Effect) values[7];
555         onmousedowneffect = (Effect) values[8];
556         onmouseupeffect = (Effect) values[9];
557         onmousemoveeffect = (Effect) values[10];
558         onmouseovereffect = (Effect) values[11];
559         onmouseouteffect = (Effect) values[12];
560         onchangeeffect = (Effect) values[13];
561         onkeypresseffect = (Effect) values[16];
562         onkeydowneffect = (Effect) values[17];
563         onkeyupeffect = (Effect) values[18];
564         currentStyle = (CurrentStyle) values[19];
565         visible = (Boolean JavaDoc) values[20];
566         autocomplete = (String JavaDoc) values[21];
567     }
568 }
569
570
571
Popular Tags