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