001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.component.html;
030:
031: import java.util.*;
032:
033: import javax.el.*;
034:
035: import javax.faces.component.*;
036: import javax.faces.context.*;
037:
038: public class HtmlSelectBooleanCheckbox extends UISelectBoolean {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlSelectBooleanCheckbox";
040:
041: private static final HashMap<String, PropEnum> _propMap = new HashMap<String, PropEnum>();
042:
043: private String _accesskey;
044: private ValueExpression _accesskeyExpr;
045:
046: private String _dir;
047: private ValueExpression _dirExpr;
048:
049: private Boolean _disabled;
050: private ValueExpression _disabledExpr;
051:
052: private String _label;
053: private ValueExpression _labelExpr;
054:
055: private String _lang;
056: private ValueExpression _langExpr;
057:
058: private String _onblur;
059: private ValueExpression _onblurExpr;
060:
061: private String _onchange;
062: private ValueExpression _onchangeExpr;
063:
064: private String _onclick;
065: private ValueExpression _onclickExpr;
066:
067: private String _ondblclick;
068: private ValueExpression _ondblclickExpr;
069:
070: private String _onfocus;
071: private ValueExpression _onfocusExpr;
072:
073: private String _onkeydown;
074: private ValueExpression _onkeydownExpr;
075:
076: private String _onkeypress;
077: private ValueExpression _onkeypressExpr;
078:
079: private String _onkeyup;
080: private ValueExpression _onkeyupExpr;
081:
082: private String _onmousedown;
083: private ValueExpression _onmousedownExpr;
084:
085: private String _onmousemove;
086: private ValueExpression _onmousemoveExpr;
087:
088: private String _onmouseout;
089: private ValueExpression _onmouseoutExpr;
090:
091: private String _onmouseover;
092: private ValueExpression _onmouseoverExpr;
093:
094: private String _onmouseup;
095: private ValueExpression _onmouseupExpr;
096:
097: private String _onselect;
098: private ValueExpression _onselectExpr;
099:
100: private Boolean _readonly;
101: private ValueExpression _readonlyExpr;
102:
103: private String _style;
104: private ValueExpression _styleExpr;
105:
106: private String _styleClass;
107: private ValueExpression _styleClassExpr;
108:
109: private String _tabindex;
110: private ValueExpression _tabindexExpr;
111:
112: private String _title;
113: private ValueExpression _titleExpr;
114:
115: public HtmlSelectBooleanCheckbox() {
116: setRendererType("javax.faces.Checkbox");
117: }
118:
119: //
120: // properties
121: //
122:
123: public String getAccesskey() {
124: if (_accesskey != null)
125: return _accesskey;
126: else if (_accesskeyExpr != null)
127: return Util.evalString(_accesskeyExpr);
128: else
129: return null;
130: }
131:
132: public void setAccesskey(String value) {
133: _accesskey = value;
134: }
135:
136: public String getDir() {
137: if (_dir != null)
138: return _dir;
139: else if (_dirExpr != null)
140: return Util.evalString(_dirExpr);
141: else
142: return null;
143: }
144:
145: public void setDir(String value) {
146: _dir = value;
147: }
148:
149: public boolean isDisabled() {
150: if (_disabled != null)
151: return _disabled;
152: else if (_disabledExpr != null)
153: return Util.evalBoolean(_disabledExpr);
154: else
155: return false;
156: }
157:
158: public void setDisabled(boolean value) {
159: _disabled = value;
160: }
161:
162: public String getLabel() {
163: if (_label != null)
164: return _label;
165: else if (_labelExpr != null)
166: return Util.evalString(_labelExpr);
167: else
168: return null;
169: }
170:
171: public void setLabel(String value) {
172: _label = value;
173: }
174:
175: public String getLang() {
176: if (_lang != null)
177: return _lang;
178: else if (_langExpr != null)
179: return Util.evalString(_langExpr);
180: else
181: return null;
182: }
183:
184: public void setLang(String value) {
185: _lang = value;
186: }
187:
188: public String getOnblur() {
189: if (_onblur != null)
190: return _onblur;
191: else if (_onblurExpr != null)
192: return Util.evalString(_onblurExpr);
193: else
194: return null;
195: }
196:
197: public void setOnblur(String value) {
198: _onblur = value;
199: }
200:
201: public String getOnchange() {
202: if (_onchange != null)
203: return _onchange;
204: else if (_onchangeExpr != null)
205: return Util.evalString(_onchangeExpr);
206: else
207: return null;
208: }
209:
210: public void setOnchange(String value) {
211: _onchange = value;
212: }
213:
214: public String getOnclick() {
215: if (_onclick != null)
216: return _onclick;
217: else if (_onclickExpr != null)
218: return Util.evalString(_onclickExpr);
219: else
220: return null;
221: }
222:
223: public void setOnclick(String value) {
224: _onclick = value;
225: }
226:
227: public String getOndblclick() {
228: if (_ondblclick != null)
229: return _ondblclick;
230: else if (_ondblclickExpr != null)
231: return Util.evalString(_ondblclickExpr);
232: else
233: return null;
234: }
235:
236: public void setOndblclick(String value) {
237: _ondblclick = value;
238: }
239:
240: public String getOnfocus() {
241: if (_onfocus != null)
242: return _onfocus;
243: else if (_onfocusExpr != null)
244: return Util.evalString(_onfocusExpr);
245: else
246: return null;
247: }
248:
249: public void setOnfocus(String value) {
250: _onfocus = value;
251: }
252:
253: public String getOnkeydown() {
254: if (_onkeydown != null)
255: return _onkeydown;
256: else if (_onkeydownExpr != null)
257: return Util.evalString(_onkeydownExpr);
258: else
259: return null;
260: }
261:
262: public void setOnkeydown(String value) {
263: _onkeydown = value;
264: }
265:
266: public String getOnkeypress() {
267: if (_onkeypress != null)
268: return _onkeypress;
269: else if (_onkeypressExpr != null)
270: return Util.evalString(_onkeypressExpr);
271: else
272: return null;
273: }
274:
275: public void setOnkeypress(String value) {
276: _onkeypress = value;
277: }
278:
279: public String getOnkeyup() {
280: if (_onkeyup != null)
281: return _onkeyup;
282: else if (_onkeyupExpr != null)
283: return Util.evalString(_onkeyupExpr);
284: else
285: return null;
286: }
287:
288: public void setOnkeyup(String value) {
289: _onkeyup = value;
290: }
291:
292: public String getOnmousedown() {
293: if (_onmousedown != null)
294: return _onmousedown;
295: else if (_onmousedownExpr != null)
296: return Util.evalString(_onmousedownExpr);
297: else
298: return null;
299: }
300:
301: public void setOnmousedown(String value) {
302: _onmousedown = value;
303: }
304:
305: public String getOnmousemove() {
306: if (_onmousemove != null)
307: return _onmousemove;
308: else if (_onmousemoveExpr != null)
309: return Util.evalString(_onmousemoveExpr);
310: else
311: return null;
312: }
313:
314: public void setOnmousemove(String value) {
315: _onmousemove = value;
316: }
317:
318: public String getOnmouseout() {
319: if (_onmouseout != null)
320: return _onmouseout;
321: else if (_onmouseoutExpr != null)
322: return Util.evalString(_onmouseoutExpr);
323: else
324: return null;
325: }
326:
327: public void setOnmouseout(String value) {
328: _onmouseout = value;
329: }
330:
331: public String getOnmouseover() {
332: if (_onmouseover != null)
333: return _onmouseover;
334: else if (_onmouseoverExpr != null)
335: return Util.evalString(_onmouseoverExpr);
336: else
337: return null;
338: }
339:
340: public void setOnmouseover(String value) {
341: _onmouseover = value;
342: }
343:
344: public String getOnmouseup() {
345: if (_onmouseup != null)
346: return _onmouseup;
347: else if (_onmouseupExpr != null)
348: return Util.evalString(_onmouseupExpr);
349: else
350: return null;
351: }
352:
353: public void setOnmouseup(String value) {
354: _onmouseup = value;
355: }
356:
357: public String getOnselect() {
358: if (_onselect != null)
359: return _onselect;
360: else if (_onselectExpr != null)
361: return Util.evalString(_onselectExpr);
362: else
363: return null;
364: }
365:
366: public void setOnselect(String value) {
367: _onselect = value;
368: }
369:
370: public boolean isReadonly() {
371: if (_readonly != null)
372: return _readonly;
373: else if (_readonlyExpr != null)
374: return Util.evalBoolean(_readonlyExpr);
375: else
376: return false;
377: }
378:
379: public void setReadonly(boolean value) {
380: _readonly = value;
381: }
382:
383: public String getStyle() {
384: if (_style != null)
385: return _style;
386: else if (_styleExpr != null)
387: return Util.evalString(_styleExpr);
388: else
389: return null;
390: }
391:
392: public void setStyle(String value) {
393: _style = value;
394: }
395:
396: public String getStyleClass() {
397: if (_styleClass != null)
398: return _styleClass;
399: else if (_styleClassExpr != null)
400: return Util.evalString(_styleClassExpr);
401: else
402: return null;
403: }
404:
405: public void setStyleClass(String value) {
406: _styleClass = value;
407: }
408:
409: public String getTabindex() {
410: if (_tabindex != null)
411: return _tabindex;
412: else if (_tabindexExpr != null)
413: return Util.evalString(_tabindexExpr);
414: else
415: return null;
416: }
417:
418: public void setTabindex(String value) {
419: _tabindex = value;
420: }
421:
422: public String getTitle() {
423: if (_title != null)
424: return _title;
425: else if (_titleExpr != null)
426: return Util.evalString(_titleExpr);
427: else
428: return null;
429: }
430:
431: public void setTitle(String value) {
432: _title = value;
433: }
434:
435: //
436: // value expression override
437: //
438:
439: /**
440: * Returns the value expression with the given name.
441: */
442: @Override
443: public ValueExpression getValueExpression(String name) {
444: PropEnum prop = _propMap.get(name);
445:
446: if (prop != null) {
447: switch (prop) {
448: case ACCESSKEY:
449: return _accesskeyExpr;
450: case DIR:
451: return _dirExpr;
452: case DISABLED:
453: return _disabledExpr;
454: case LABEL:
455: return _labelExpr;
456: case LANG:
457: return _langExpr;
458: case ONBLUR:
459: return _onblurExpr;
460: case ONCHANGE:
461: return _onchangeExpr;
462: case ONCLICK:
463: return _onclickExpr;
464: case ONDBLCLICK:
465: return _ondblclickExpr;
466: case ONFOCUS:
467: return _onfocusExpr;
468: case ONKEYDOWN:
469: return _onkeydownExpr;
470: case ONKEYPRESS:
471: return _onkeypressExpr;
472: case ONKEYUP:
473: return _onkeyupExpr;
474: case ONMOUSEDOWN:
475: return _onmousedownExpr;
476: case ONMOUSEMOVE:
477: return _onmousemoveExpr;
478: case ONMOUSEOUT:
479: return _onmouseoutExpr;
480: case ONMOUSEOVER:
481: return _onmouseoverExpr;
482: case ONMOUSEUP:
483: return _onmouseupExpr;
484: case ONSELECT:
485: return _onselectExpr;
486: case READONLY:
487: return _readonlyExpr;
488: case STYLE:
489: return _styleExpr;
490: case STYLE_CLASS:
491: return _styleClassExpr;
492: case TABINDEX:
493: return _tabindexExpr;
494: case TITLE:
495: return _titleExpr;
496: }
497: }
498:
499: return super .getValueExpression(name);
500: }
501:
502: /**
503: * Sets the value expression with the given name.
504: */
505: @Override
506: public void setValueExpression(String name, ValueExpression expr) {
507: PropEnum prop = _propMap.get(name);
508:
509: if (prop != null) {
510: switch (prop) {
511: case ACCESSKEY:
512: if (expr != null && expr.isLiteralText()) {
513: _accesskey = Util.evalString(expr);
514: return;
515: } else
516: _accesskeyExpr = expr;
517: break;
518:
519: case DIR:
520: if (expr != null && expr.isLiteralText()) {
521: _dir = Util.evalString(expr);
522: return;
523: } else
524: _dirExpr = expr;
525: break;
526:
527: case DISABLED:
528: if (expr != null && expr.isLiteralText()) {
529: _disabled = Util.evalBoolean(expr);
530: return;
531: } else
532: _disabledExpr = expr;
533: break;
534:
535: case LABEL:
536: if (expr != null && expr.isLiteralText()) {
537: _label = Util.evalString(expr);
538: return;
539: } else
540: _labelExpr = expr;
541: break;
542:
543: case LANG:
544: if (expr != null && expr.isLiteralText()) {
545: _lang = Util.evalString(expr);
546: return;
547: } else
548: _langExpr = expr;
549: break;
550:
551: case ONBLUR:
552: if (expr != null && expr.isLiteralText()) {
553: _onblur = Util.evalString(expr);
554: return;
555: } else
556: _onblurExpr = expr;
557: break;
558:
559: case ONCHANGE:
560: if (expr != null && expr.isLiteralText()) {
561: _onchange = Util.evalString(expr);
562: return;
563: } else
564: _onchangeExpr = expr;
565: break;
566:
567: case ONCLICK:
568: if (expr != null && expr.isLiteralText()) {
569: _onclick = Util.evalString(expr);
570: return;
571: } else
572: _onclickExpr = expr;
573: break;
574:
575: case ONDBLCLICK:
576: if (expr != null && expr.isLiteralText()) {
577: _ondblclick = Util.evalString(expr);
578: return;
579: } else
580: _ondblclickExpr = expr;
581: break;
582:
583: case ONFOCUS:
584: if (expr != null && expr.isLiteralText()) {
585: _onfocus = Util.evalString(expr);
586: return;
587: } else
588: _onfocusExpr = expr;
589: break;
590:
591: case ONKEYDOWN:
592: if (expr != null && expr.isLiteralText()) {
593: _onkeydown = Util.evalString(expr);
594: return;
595: } else
596: _onkeydownExpr = expr;
597: break;
598:
599: case ONKEYPRESS:
600: if (expr != null && expr.isLiteralText()) {
601: _onkeypress = Util.evalString(expr);
602: return;
603: } else
604: _onkeypressExpr = expr;
605: break;
606:
607: case ONKEYUP:
608: if (expr != null && expr.isLiteralText()) {
609: _onkeyup = Util.evalString(expr);
610: return;
611: } else
612: _onkeyupExpr = expr;
613: break;
614:
615: case ONMOUSEDOWN:
616: if (expr != null && expr.isLiteralText()) {
617: _onmousedown = Util.evalString(expr);
618: return;
619: } else
620: _onmousedownExpr = expr;
621: break;
622:
623: case ONMOUSEMOVE:
624: if (expr != null && expr.isLiteralText()) {
625: _onmousemove = Util.evalString(expr);
626: return;
627: } else
628: _onmousemoveExpr = expr;
629: break;
630:
631: case ONMOUSEOUT:
632: if (expr != null && expr.isLiteralText()) {
633: _onmouseout = Util.evalString(expr);
634: return;
635: } else
636: _onmouseoutExpr = expr;
637: break;
638:
639: case ONMOUSEOVER:
640: if (expr != null && expr.isLiteralText()) {
641: _onmouseover = Util.evalString(expr);
642: return;
643: } else
644: _onmouseoverExpr = expr;
645: break;
646:
647: case ONMOUSEUP:
648: if (expr != null && expr.isLiteralText()) {
649: _onmouseup = Util.evalString(expr);
650: return;
651: } else
652: _onmouseupExpr = expr;
653: break;
654:
655: case ONSELECT:
656: if (expr != null && expr.isLiteralText()) {
657: _onselect = Util.evalString(expr);
658: return;
659: } else
660: _onselectExpr = expr;
661: break;
662:
663: case READONLY:
664: if (expr != null && expr.isLiteralText()) {
665: _readonly = Util.evalBoolean(expr);
666: return;
667: } else
668: _readonlyExpr = expr;
669: break;
670:
671: case STYLE:
672: if (expr != null && expr.isLiteralText()) {
673: _style = Util.evalString(expr);
674: return;
675: } else
676: _styleExpr = expr;
677: break;
678:
679: case STYLE_CLASS:
680: if (expr != null && expr.isLiteralText()) {
681: _styleClass = Util.evalString(expr);
682: return;
683: } else
684: _styleClassExpr = expr;
685: break;
686:
687: case TABINDEX:
688: if (expr != null && expr.isLiteralText()) {
689: _tabindex = Util.evalString(expr);
690: return;
691: } else
692: _tabindexExpr = expr;
693: break;
694:
695: case TITLE:
696: if (expr != null && expr.isLiteralText()) {
697: _title = Util.evalString(expr);
698: return;
699: } else
700: _titleExpr = expr;
701: break;
702: }
703: }
704:
705: super .setValueExpression(name, expr);
706: }
707:
708: //
709: // state
710: //
711:
712: public Object saveState(FacesContext context) {
713: Object parent = super .saveState(context);
714:
715: return new Object[] { parent,
716:
717: _accesskey, _dir, _disabled, _label, _lang,
718:
719: _onblur, _onchange, _onclick, _ondblclick, _onfocus,
720:
721: _onkeydown, _onkeypress, _onkeyup,
722:
723: _onmousedown, _onmousemove, _onmouseout, _onmouseover,
724: _onmouseup,
725:
726: _onselect,
727:
728: _readonly,
729:
730: _style, _styleClass, _tabindex, _title, };
731: }
732:
733: public void restoreState(FacesContext context, Object value) {
734: Object[] state = (Object[]) value;
735:
736: int i = 0;
737:
738: if (state != null)
739: super .restoreState(context, state[i++]);
740:
741: _accesskey = (String) state[i++];
742: _dir = (String) state[i++];
743: _disabled = (Boolean) state[i++];
744: _label = (String) state[i++];
745: _lang = (String) state[i++];
746: _onblur = (String) state[i++];
747: _onchange = (String) state[i++];
748: _onclick = (String) state[i++];
749: _ondblclick = (String) state[i++];
750: _onfocus = (String) state[i++];
751: _onkeydown = (String) state[i++];
752: _onkeypress = (String) state[i++];
753: _onkeyup = (String) state[i++];
754: _onmousedown = (String) state[i++];
755: _onmousemove = (String) state[i++];
756: _onmouseout = (String) state[i++];
757: _onmouseover = (String) state[i++];
758: _onmouseup = (String) state[i++];
759: _onselect = (String) state[i++];
760: _readonly = (Boolean) state[i++];
761: _style = (String) state[i++];
762: _styleClass = (String) state[i++];
763: _tabindex = (String) state[i++];
764: _title = (String) state[i++];
765: }
766:
767: //
768: // utility
769: //
770:
771: private enum PropEnum {
772: ACCESSKEY, DIR, DISABLED, LABEL, LANG, ONBLUR, ONCHANGE, ONCLICK, ONDBLCLICK, ONFOCUS, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEMOVE, ONMOUSEOUT, ONMOUSEOVER, ONMOUSEUP, ONSELECT, READONLY, STYLE, STYLE_CLASS, TABINDEX, TITLE,
773: }
774:
775: static {
776: _propMap.put("accesskey", PropEnum.ACCESSKEY);
777: _propMap.put("dir", PropEnum.DIR);
778: _propMap.put("disabled", PropEnum.DISABLED);
779: _propMap.put("label", PropEnum.LABEL);
780: _propMap.put("lang", PropEnum.LANG);
781: _propMap.put("onblur", PropEnum.ONBLUR);
782: _propMap.put("onchange", PropEnum.ONCHANGE);
783: _propMap.put("onclick", PropEnum.ONCLICK);
784: _propMap.put("ondblclick", PropEnum.ONDBLCLICK);
785: _propMap.put("onfocus", PropEnum.ONFOCUS);
786: _propMap.put("onkeydown", PropEnum.ONKEYDOWN);
787: _propMap.put("onkeypress", PropEnum.ONKEYPRESS);
788: _propMap.put("onkeyup", PropEnum.ONKEYUP);
789: _propMap.put("onmousedown", PropEnum.ONMOUSEDOWN);
790: _propMap.put("onmousemove", PropEnum.ONMOUSEMOVE);
791: _propMap.put("onmouseover", PropEnum.ONMOUSEOVER);
792: _propMap.put("onmouseout", PropEnum.ONMOUSEOUT);
793: _propMap.put("onmouseup", PropEnum.ONMOUSEUP);
794: _propMap.put("onselect", PropEnum.ONSELECT);
795: _propMap.put("readonly", PropEnum.READONLY);
796: _propMap.put("style", PropEnum.STYLE);
797: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
798: _propMap.put("tabindex", PropEnum.TABINDEX);
799: _propMap.put("title", PropEnum.TITLE);
800: }
801: }
|