001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.ext;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.IceExtended;
038: import com.icesoft.faces.component.ext.taglib.Util;
039: import com.icesoft.faces.context.BridgeFacesContext;
040: import com.icesoft.faces.context.effects.CurrentStyle;
041: import com.icesoft.faces.context.effects.Effect;
042: import com.icesoft.faces.context.effects.JavascriptContext;
043:
044: import javax.faces.context.FacesContext;
045: import javax.faces.el.ValueBinding;
046:
047: /**
048: * This is an extension of javax.faces.component.html.HtmlSelectOneRadio, which
049: * provides some additional behavior to this component such as: <ul> <li>default
050: * classes for enabled and disabled state</li> <li>provides partial submit
051: * mechanism</li> <li>changes the component's enabled and rendered state based
052: * on the authentication</li> <li>adds effects to the component</li> <ul>
053: */
054: public class HtmlSelectOneRadio extends
055: javax.faces.component.html.HtmlSelectOneRadio implements
056: IceExtended {
057:
058: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlSelectOneRadio";
059: public static final String RENDERER_TYPE = "com.icesoft.faces.Radio";
060: private static final boolean DEFAULT_VISIBLE = true;
061: private String styleClass = null;
062: private Boolean partialSubmit = null;
063: private String enabledOnUserRole = null;
064: private String renderedOnUserRole = null;
065: private Effect effect;
066: private Boolean visible = null;
067:
068: private CurrentStyle currentStyle;
069:
070: private Effect onclickeffect;
071: private Effect ondblclickeffect;
072: private Effect onmousedowneffect;
073: private Effect onmouseupeffect;
074: private Effect onmousemoveeffect;
075: private Effect onmouseovereffect;
076: private Effect onmouseouteffect;
077: private Effect onchangeeffect;
078: private Effect onkeypresseffect;
079: private Effect onkeydowneffect;
080: private Effect onkeyupeffect;
081:
082: public HtmlSelectOneRadio() {
083: super ();
084: setRendererType(RENDERER_TYPE);
085: }
086:
087: /**
088: * This method is used to communicate a focus request from the application
089: * to the client browser.
090: */
091: public void requestFocus() {
092: ((BridgeFacesContext) FacesContext.getCurrentInstance())
093: .setFocusId("null");
094: JavascriptContext.focus(FacesContext.getCurrentInstance(), this
095: .getClientId(FacesContext.getCurrentInstance()));
096: }
097:
098: public void setValueBinding(String s, ValueBinding vb) {
099: if (s != null && s.indexOf("effect") != -1) {
100: // If this is an effect attribute make sure Ice Extras is included
101: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
102: getFacesContext());
103: }
104: super .setValueBinding(s, vb);
105: }
106:
107: /**
108: * <p>Set the value of the <code>partialSubmit</code> property.</p>
109: */
110: public void setPartialSubmit(boolean partialSubmit) {
111: this .partialSubmit = Boolean.valueOf(partialSubmit);
112: }
113:
114: /**
115: * <p>Return the value of the <code>partialSubmit</code> property.</p>
116: */
117: public boolean getPartialSubmit() {
118: if (partialSubmit != null) {
119: return partialSubmit.booleanValue();
120: }
121: ValueBinding vb = getValueBinding("partialSubmit");
122: Boolean boolVal = vb != null ? (Boolean) vb
123: .getValue(getFacesContext()) : null;
124: return boolVal != null ? boolVal.booleanValue() : Util
125: .isParentPartialSubmit(this );
126: }
127:
128: /**
129: * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
130: */
131: public void setEnabledOnUserRole(String enabledOnUserRole) {
132: this .enabledOnUserRole = enabledOnUserRole;
133: }
134:
135: /**
136: * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
137: */
138: public String getEnabledOnUserRole() {
139: if (enabledOnUserRole != null) {
140: return enabledOnUserRole;
141: }
142: ValueBinding vb = getValueBinding("enabledOnUserRole");
143: return vb != null ? (String) vb.getValue(getFacesContext())
144: : null;
145: }
146:
147: /**
148: * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
149: */
150: public void setRenderedOnUserRole(String renderedOnUserRole) {
151: this .renderedOnUserRole = renderedOnUserRole;
152: }
153:
154: /**
155: * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
156: */
157: public String getRenderedOnUserRole() {
158: if (renderedOnUserRole != null) {
159: return renderedOnUserRole;
160: }
161: ValueBinding vb = getValueBinding("renderedOnUserRole");
162: return vb != null ? (String) vb.getValue(getFacesContext())
163: : null;
164: }
165:
166: /**
167: * <p>Set the value of the <code>styleClass</code> property.</p>
168: */
169: public void setStyleClass(String styleClass) {
170: this .styleClass = styleClass;
171: }
172:
173: /**
174: * <p>Return the value of the <code>styleClass</code> property.</p>
175: */
176: public String getStyleClass() {
177: return Util.getQualifiedStyleClass(this , styleClass,
178: CSS_DEFAULT.SELECT_ONE_RADIO_DEFAULT_STYLE_CLASS,
179: "styleClass", isDisabled());
180: }
181:
182: /**
183: * <p>Return the value of the <code>rendered</code> property.</p>
184: */
185: public boolean isRendered() {
186: if (!Util.isRenderedOnUserRole(this )) {
187: return false;
188: }
189: return super .isRendered();
190: }
191:
192: /**
193: * <p>Return the value of the <code>disabled</code> property.</p>
194: */
195: public boolean isDisabled() {
196: if (!Util.isEnabledOnUserRole(this )) {
197: return true;
198: } else {
199: return super .isDisabled();
200: }
201: }
202:
203: /**
204: * <p>Return the value of the <code>onclickeffect</code> property.</p>
205: */
206: public Effect getOnclickeffect() {
207: if (onclickeffect != null) {
208: return onclickeffect;
209: }
210: ValueBinding vb = getValueBinding("onclickeffect");
211:
212: return vb != null ? (Effect) vb.getValue(getFacesContext())
213: : null;
214: }
215:
216: /**
217: * <p>Set the value of the <code>onclickeffect</code> property.</p>
218: */
219: public void setOnclickeffect(Effect onclickeffect) {
220: this .onclickeffect = onclickeffect;
221: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
222: getFacesContext());
223: }
224:
225: /**
226: * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
227: */
228: public Effect getOndblclickeffect() {
229: if (ondblclickeffect != null) {
230: return ondblclickeffect;
231: }
232: ValueBinding vb = getValueBinding("ondblclickeffect");
233:
234: return vb != null ? (Effect) vb.getValue(getFacesContext())
235: : null;
236: }
237:
238: /**
239: * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
240: */
241: public void setOndblclickeffect(Effect ondblclickeffect) {
242: this .ondblclickeffect = ondblclickeffect;
243: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
244: getFacesContext());
245: }
246:
247: /**
248: * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
249: */
250: public Effect getOnmousedowneffect() {
251: if (onmousedowneffect != null) {
252: return onmousedowneffect;
253: }
254: ValueBinding vb = getValueBinding("onmousedowneffect");
255:
256: return vb != null ? (Effect) vb.getValue(getFacesContext())
257: : 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.includeLib(JavascriptContext.ICE_EXTRAS,
266: 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())
279: : null;
280: }
281:
282: /**
283: * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
284: */
285: public void setOnmouseupeffect(Effect onmouseupeffect) {
286: this .onmouseupeffect = onmouseupeffect;
287: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
288: getFacesContext());
289: }
290:
291: /**
292: * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
293: */
294: public Effect getOnmousemoveeffect() {
295: if (onmousemoveeffect != null) {
296: return onmousemoveeffect;
297: }
298: ValueBinding vb = getValueBinding("onmousemoveeffect");
299:
300: return vb != null ? (Effect) vb.getValue(getFacesContext())
301: : null;
302: }
303:
304: /**
305: * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
306: */
307: public void setOnmousemoveeffect(Effect onmousemoveeffect) {
308: this .onmousemoveeffect = onmousemoveeffect;
309: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
310: getFacesContext());
311: }
312:
313: /**
314: * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
315: */
316: public Effect getOnmouseovereffect() {
317: if (onmouseovereffect != null) {
318: return onmouseovereffect;
319: }
320: ValueBinding vb = getValueBinding("onmouseovereffect");
321:
322: return vb != null ? (Effect) vb.getValue(getFacesContext())
323: : null;
324: }
325:
326: /**
327: * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
328: */
329: public void setOnmouseovereffect(Effect onmouseovereffect) {
330: this .onmouseovereffect = onmouseovereffect;
331: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
332: getFacesContext());
333: }
334:
335: /**
336: * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
337: */
338: public Effect getOnmouseouteffect() {
339: if (onmouseouteffect != null) {
340: return onmouseouteffect;
341: }
342: ValueBinding vb = getValueBinding("onmouseouteffect");
343:
344: return vb != null ? (Effect) vb.getValue(getFacesContext())
345: : null;
346: }
347:
348: /**
349: * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
350: */
351: public void setOnmouseouteffect(Effect onmouseouteffect) {
352: this .onmouseouteffect = onmouseouteffect;
353: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
354: getFacesContext());
355: }
356:
357: /**
358: * <p>Return the value of the <code>onchangeeffect</code> property.</p>
359: */
360: public Effect getOnchangeeffect() {
361: if (onchangeeffect != null) {
362: return onchangeeffect;
363: }
364: ValueBinding vb = getValueBinding("onchangeeffect");
365:
366: return vb != null ? (Effect) vb.getValue(getFacesContext())
367: : null;
368: }
369:
370: /**
371: * <p>Set the value of the <code>onchangeeffect</code> property.</p>
372: */
373: public void setOnchangeeffect(Effect onchangeeffect) {
374: this .onchangeeffect = onchangeeffect;
375: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
376: getFacesContext());
377: }
378:
379: /**
380: * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
381: */
382: public Effect getOnkeypresseffect() {
383: if (onkeypresseffect != null) {
384: return onkeypresseffect;
385: }
386: ValueBinding vb = getValueBinding("onkeypresseffect");
387:
388: return vb != null ? (Effect) vb.getValue(getFacesContext())
389: : null;
390: }
391:
392: /**
393: * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
394: */
395: public void setOnkeypresseffect(Effect onkeypresseffect) {
396: this .onkeypresseffect = onkeypresseffect;
397: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
398: getFacesContext());
399: }
400:
401: /**
402: * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
403: */
404: public Effect getOnkeydowneffect() {
405: if (onkeydowneffect != null) {
406: return onkeydowneffect;
407: }
408: ValueBinding vb = getValueBinding("onkeydowneffect");
409:
410: return vb != null ? (Effect) vb.getValue(getFacesContext())
411: : null;
412: }
413:
414: /**
415: * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
416: */
417: public void setOnkeydowneffect(Effect onkeydowneffect) {
418: this .onkeydowneffect = onkeydowneffect;
419: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
420: getFacesContext());
421: }
422:
423: /**
424: * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
425: */
426: public Effect getOnkeyupeffect() {
427: if (onkeyupeffect != null) {
428: return onkeyupeffect;
429: }
430: ValueBinding vb = getValueBinding("onkeyupeffect");
431:
432: return vb != null ? (Effect) vb.getValue(getFacesContext())
433: : null;
434: }
435:
436: /**
437: * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
438: */
439: public void setOnkeyupeffect(Effect onkeyupeffect) {
440: this .onkeyupeffect = onkeyupeffect;
441: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
442: getFacesContext());
443: }
444:
445: /**
446: * <p>Return the value of the <code>currentStyle</code> property.</p>
447: */
448: public CurrentStyle getCurrentStyle() {
449: return currentStyle;
450: }
451:
452: /**
453: * <p>Set the value of the <code>currentStyle</code> property.</p>
454: */
455: public void setCurrentStyle(CurrentStyle currentStyle) {
456: this .currentStyle = currentStyle;
457: }
458:
459: /**
460: * <p>Set the value of the <code>visible</code> property.</p>
461: */
462: public void setVisible(boolean visible) {
463: this .visible = Boolean.valueOf(visible);
464: }
465:
466: /**
467: * <p>Return the value of the <code>visible</code> property.</p>
468: */
469: public boolean getVisible() {
470: if (visible != null) {
471: return visible.booleanValue();
472: }
473: ValueBinding vb = getValueBinding("visible");
474: Boolean boolVal = vb != null ? (Boolean) vb
475: .getValue(getFacesContext()) : null;
476: return boolVal != null ? boolVal.booleanValue()
477: : DEFAULT_VISIBLE;
478: }
479:
480: private String autocomplete;
481:
482: /**
483: * <p>Set the value of the <code>autocomplete</code> property.</p>
484: */
485: public void setAutocomplete(String autocomplete) {
486: this .autocomplete = autocomplete;
487: }
488:
489: /**
490: * <p>Return the value of the <code>autocomplete</code> property.</p>
491: */
492: public String getAutocomplete() {
493: if (autocomplete != null) {
494: return autocomplete;
495: }
496: ValueBinding vb = getValueBinding("autocomplete");
497: return vb != null ? (String) vb.getValue(getFacesContext())
498: : null;
499: }
500:
501: /**
502: * <p>Set the value of the <code>effect</code> property.</p>
503: */
504: public void setEffect(Effect effect) {
505: this .effect = effect;
506: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
507: getFacesContext());
508: }
509:
510: /**
511: * <p>Return the value of the <code>effect</code> property.</p>
512: */
513: public Effect getEffect() {
514: if (effect != null) {
515: return effect;
516: }
517: ValueBinding vb = getValueBinding("effect");
518: return vb != null ? (Effect) vb.getValue(getFacesContext())
519: : null;
520: }
521:
522: /**
523: * <p>Gets the state of the instance as a <code>Serializable</code>
524: * Object.</p>
525: */
526: public Object saveState(FacesContext context) {
527: Object values[] = new Object[22];
528: values[0] = super .saveState(context);
529: values[1] = partialSubmit;
530: values[2] = enabledOnUserRole;
531: values[3] = renderedOnUserRole;
532: values[4] = styleClass;
533: values[5] = effect;
534: values[6] = onclickeffect;
535: values[7] = ondblclickeffect;
536: values[8] = onmousedowneffect;
537: values[9] = onmouseupeffect;
538: values[10] = onmousemoveeffect;
539: values[11] = onmouseovereffect;
540: values[12] = onmouseouteffect;
541: values[13] = onchangeeffect;
542: values[16] = onkeypresseffect;
543: values[17] = onkeydowneffect;
544: values[18] = onkeyupeffect;
545: values[19] = currentStyle;
546: values[20] = visible;
547: values[21] = autocomplete;
548: return ((Object) (values));
549: }
550:
551: /**
552: * <p>Perform any processing required to restore the state from the entries
553: * in the state Object.</p>
554: */
555: public void restoreState(FacesContext context, Object state) {
556: Object values[] = (Object[]) state;
557: super .restoreState(context, values[0]);
558: partialSubmit = (Boolean) values[1];
559: enabledOnUserRole = (String) values[2];
560: renderedOnUserRole = (String) values[3];
561: styleClass = (String) values[4];
562: effect = (Effect) values[5];
563: onclickeffect = (Effect) values[6];
564: ondblclickeffect = (Effect) values[7];
565: onmousedowneffect = (Effect) values[8];
566: onmouseupeffect = (Effect) values[9];
567: onmousemoveeffect = (Effect) values[10];
568: onmouseovereffect = (Effect) values[11];
569: onmouseouteffect = (Effect) values[12];
570: onchangeeffect = (Effect) values[13];
571: onkeypresseffect = (Effect) values[16];
572: onkeydowneffect = (Effect) values[17];
573: onkeyupeffect = (Effect) values[18];
574: currentStyle = (CurrentStyle) values[19];
575: visible = (Boolean) values[20];
576: autocomplete = (String) values[21];
577: }
578: }
|