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 HtmlForm extends UIForm {
039: public static final String COMPONENT_TYPE = "javax.faces.HtmlForm";
040:
041: private static final HashMap<String, PropEnum> _propMap = new HashMap<String, PropEnum>();
042:
043: private String _accept;
044: private ValueExpression _acceptExpr;
045:
046: private String _acceptcharset;
047: private ValueExpression _acceptcharsetExpr;
048:
049: private String _dir;
050: private ValueExpression _dirExpr;
051:
052: private String _enctype;
053: private ValueExpression _enctypeExpr;
054:
055: private String _lang;
056: private ValueExpression _langExpr;
057:
058: private String _onclick;
059: private ValueExpression _onclickExpr;
060:
061: private String _ondblclick;
062: private ValueExpression _ondblclickExpr;
063:
064: private String _onkeydown;
065: private ValueExpression _onkeydownExpr;
066:
067: private String _onkeypress;
068: private ValueExpression _onkeypressExpr;
069:
070: private String _onkeyup;
071: private ValueExpression _onkeyupExpr;
072:
073: private String _onmousedown;
074: private ValueExpression _onmousedownExpr;
075:
076: private String _onmousemove;
077: private ValueExpression _onmousemoveExpr;
078:
079: private String _onmouseout;
080: private ValueExpression _onmouseoutExpr;
081:
082: private String _onmouseover;
083: private ValueExpression _onmouseoverExpr;
084:
085: private String _onmouseup;
086: private ValueExpression _onmouseupExpr;
087:
088: private String _onreset;
089: private ValueExpression _onresetExpr;
090:
091: private String _onsubmit;
092: private ValueExpression _onsubmitExpr;
093:
094: private String _style;
095: private ValueExpression _styleExpr;
096:
097: private String _styleClass;
098: private ValueExpression _styleClassExpr;
099:
100: private String _target;
101: private ValueExpression _targetExpr;
102:
103: private String _title;
104: private ValueExpression _titleExpr;
105:
106: public HtmlForm() {
107: setRendererType("javax.faces.Form");
108: }
109:
110: //
111: // properties
112: //
113:
114: public String getAccept() {
115: if (_accept != null)
116: return _accept;
117: else if (_acceptExpr != null)
118: return Util.evalString(_acceptExpr);
119: else
120: return null;
121: }
122:
123: public void setAccept(String value) {
124: _accept = value;
125: }
126:
127: public String getAcceptcharset() {
128: if (_acceptcharset != null)
129: return _acceptcharset;
130: else if (_acceptcharsetExpr != null)
131: return Util.evalString(_acceptcharsetExpr);
132: else
133: return null;
134: }
135:
136: public void setAcceptcharset(String value) {
137: _acceptcharset = value;
138: }
139:
140: public String getDir() {
141: if (_dir != null)
142: return _dir;
143: else if (_dirExpr != null)
144: return Util.evalString(_dirExpr);
145: else
146: return null;
147: }
148:
149: public void setDir(String value) {
150: _dir = value;
151: }
152:
153: public String getEnctype() {
154: if (_enctype != null)
155: return _enctype;
156: else if (_enctypeExpr != null)
157: return Util.evalString(_enctypeExpr);
158: else
159: return null;
160: }
161:
162: public void setEnctype(String value) {
163: _enctype = value;
164: }
165:
166: public String getLang() {
167: if (_lang != null)
168: return _lang;
169: else if (_langExpr != null)
170: return Util.evalString(_langExpr);
171: else
172: return null;
173: }
174:
175: public void setLang(String value) {
176: _lang = value;
177: }
178:
179: public String getOnclick() {
180: if (_onclick != null)
181: return _onclick;
182: else if (_onclickExpr != null)
183: return Util.evalString(_onclickExpr);
184: else
185: return null;
186: }
187:
188: public void setOnclick(String value) {
189: _onclick = value;
190: }
191:
192: public String getOndblclick() {
193: if (_ondblclick != null)
194: return _ondblclick;
195: else if (_ondblclickExpr != null)
196: return Util.evalString(_ondblclickExpr);
197: else
198: return null;
199: }
200:
201: public void setOndblclick(String value) {
202: _ondblclick = value;
203: }
204:
205: public String getOnkeydown() {
206: if (_onkeydown != null)
207: return _onkeydown;
208: else if (_onkeydownExpr != null)
209: return Util.evalString(_onkeydownExpr);
210: else
211: return null;
212: }
213:
214: public void setOnkeydown(String value) {
215: _onkeydown = value;
216: }
217:
218: public String getOnkeypress() {
219: if (_onkeypress != null)
220: return _onkeypress;
221: else if (_onkeypressExpr != null)
222: return Util.evalString(_onkeypressExpr);
223: else
224: return null;
225: }
226:
227: public void setOnkeypress(String value) {
228: _onkeypress = value;
229: }
230:
231: public String getOnkeyup() {
232: if (_onkeyup != null)
233: return _onkeyup;
234: else if (_onkeyupExpr != null)
235: return Util.evalString(_onkeyupExpr);
236: else
237: return null;
238: }
239:
240: public void setOnkeyup(String value) {
241: _onkeyup = value;
242: }
243:
244: public String getOnmousedown() {
245: if (_onmousedown != null)
246: return _onmousedown;
247: else if (_onmousedownExpr != null)
248: return Util.evalString(_onmousedownExpr);
249: else
250: return null;
251: }
252:
253: public void setOnmousedown(String value) {
254: _onmousedown = value;
255: }
256:
257: public String getOnmousemove() {
258: if (_onmousemove != null)
259: return _onmousemove;
260: else if (_onmousemoveExpr != null)
261: return Util.evalString(_onmousemoveExpr);
262: else
263: return null;
264: }
265:
266: public void setOnmousemove(String value) {
267: _onmousemove = value;
268: }
269:
270: public String getOnmouseout() {
271: if (_onmouseout != null)
272: return _onmouseout;
273: else if (_onmouseoutExpr != null)
274: return Util.evalString(_onmouseoutExpr);
275: else
276: return null;
277: }
278:
279: public void setOnmouseout(String value) {
280: _onmouseout = value;
281: }
282:
283: public String getOnmouseover() {
284: if (_onmouseover != null)
285: return _onmouseover;
286: else if (_onmouseoverExpr != null)
287: return Util.evalString(_onmouseoverExpr);
288: else
289: return null;
290: }
291:
292: public void setOnmouseover(String value) {
293: _onmouseover = value;
294: }
295:
296: public String getOnmouseup() {
297: if (_onmouseup != null)
298: return _onmouseup;
299: else if (_onmouseupExpr != null)
300: return Util.evalString(_onmouseupExpr);
301: else
302: return null;
303: }
304:
305: public void setOnmouseup(String value) {
306: _onmouseup = value;
307: }
308:
309: public String getOnreset() {
310: if (_onreset != null)
311: return _onreset;
312: else if (_onresetExpr != null)
313: return Util.evalString(_onresetExpr);
314: else
315: return null;
316: }
317:
318: public void setOnreset(String value) {
319: _onreset = value;
320: }
321:
322: public String getOnsubmit() {
323: if (_onsubmit != null)
324: return _onsubmit;
325: else if (_onsubmitExpr != null)
326: return Util.evalString(_onsubmitExpr);
327: else
328: return null;
329: }
330:
331: public void setOnsubmit(String value) {
332: _onsubmit = value;
333: }
334:
335: public String getStyle() {
336: if (_style != null)
337: return _style;
338: else if (_styleExpr != null)
339: return Util.evalString(_styleExpr);
340: else
341: return null;
342: }
343:
344: public void setStyle(String value) {
345: _style = value;
346: }
347:
348: public String getStyleClass() {
349: if (_styleClass != null)
350: return _styleClass;
351: else if (_styleClassExpr != null)
352: return Util.evalString(_styleClassExpr);
353: else
354: return null;
355: }
356:
357: public void setStyleClass(String value) {
358: _styleClass = value;
359: }
360:
361: public String getTarget() {
362: if (_target != null)
363: return _target;
364: else if (_targetExpr != null)
365: return Util.evalString(_targetExpr);
366: else
367: return null;
368: }
369:
370: public void setTarget(String value) {
371: _target = value;
372: }
373:
374: public String getTitle() {
375: if (_title != null)
376: return _title;
377: else if (_titleExpr != null)
378: return Util.evalString(_titleExpr);
379: else
380: return null;
381: }
382:
383: public void setTitle(String value) {
384: _title = value;
385: }
386:
387: //
388: // value expression override
389: //
390:
391: /**
392: * Returns the value expression with the given name.
393: */
394: @Override
395: public ValueExpression getValueExpression(String name) {
396: PropEnum prop = _propMap.get(name);
397:
398: if (prop != null) {
399: switch (prop) {
400: case ACCEPT:
401: return _acceptExpr;
402: case ACCEPTCHARSET:
403: return _acceptcharsetExpr;
404: case DIR:
405: return _dirExpr;
406: case ENCTYPE:
407: return _enctypeExpr;
408: case LANG:
409: return _langExpr;
410: case ONCLICK:
411: return _onclickExpr;
412: case ONDBLCLICK:
413: return _ondblclickExpr;
414: case ONKEYDOWN:
415: return _onkeydownExpr;
416: case ONKEYPRESS:
417: return _onkeypressExpr;
418: case ONKEYUP:
419: return _onkeyupExpr;
420: case ONMOUSEDOWN:
421: return _onmousedownExpr;
422: case ONMOUSEMOVE:
423: return _onmousemoveExpr;
424: case ONMOUSEOUT:
425: return _onmouseoutExpr;
426: case ONMOUSEOVER:
427: return _onmouseoverExpr;
428: case ONMOUSEUP:
429: return _onmouseupExpr;
430: case ONRESET:
431: return _onresetExpr;
432: case ONSUBMIT:
433: return _onsubmitExpr;
434: case STYLE:
435: return _styleExpr;
436: case STYLE_CLASS:
437: return _styleClassExpr;
438: case TARGET:
439: return _targetExpr;
440: case TITLE:
441: return _titleExpr;
442: }
443: }
444:
445: return super .getValueExpression(name);
446: }
447:
448: /**
449: * Sets the value expression with the given name.
450: */
451: @Override
452: public void setValueExpression(String name, ValueExpression expr) {
453: PropEnum prop = _propMap.get(name);
454:
455: if (prop != null) {
456: switch (prop) {
457: case ACCEPT:
458: if (expr != null && expr.isLiteralText()) {
459: _accept = Util.evalString(expr);
460: return;
461: } else
462: _acceptExpr = expr;
463: break;
464:
465: case ACCEPTCHARSET:
466: if (expr != null && expr.isLiteralText()) {
467: _acceptcharset = Util.evalString(expr);
468: return;
469: } else
470: _acceptcharsetExpr = expr;
471: break;
472:
473: case DIR:
474: if (expr != null && expr.isLiteralText()) {
475: _dir = Util.evalString(expr);
476: return;
477: } else
478: _dirExpr = expr;
479: break;
480:
481: case ENCTYPE:
482: if (expr != null && expr.isLiteralText()) {
483: _enctype = Util.evalString(expr);
484: return;
485: } else
486: _enctypeExpr = expr;
487: break;
488:
489: case LANG:
490: if (expr != null && expr.isLiteralText()) {
491: _lang = Util.evalString(expr);
492: return;
493: } else
494: _langExpr = expr;
495: break;
496:
497: case ONCLICK:
498: if (expr != null && expr.isLiteralText()) {
499: _onclick = Util.evalString(expr);
500: return;
501: } else
502: _onclickExpr = expr;
503: break;
504:
505: case ONDBLCLICK:
506: if (expr != null && expr.isLiteralText()) {
507: _ondblclick = Util.evalString(expr);
508: return;
509: } else
510: _ondblclickExpr = expr;
511: break;
512:
513: case ONKEYDOWN:
514: if (expr != null && expr.isLiteralText()) {
515: _onkeydown = Util.evalString(expr);
516: return;
517: } else
518: _onkeydownExpr = expr;
519: break;
520:
521: case ONKEYPRESS:
522: if (expr != null && expr.isLiteralText()) {
523: _onkeypress = Util.evalString(expr);
524: return;
525: } else
526: _onkeypressExpr = expr;
527: break;
528:
529: case ONKEYUP:
530: if (expr != null && expr.isLiteralText()) {
531: _onkeyup = Util.evalString(expr);
532: return;
533: } else
534: _onkeyupExpr = expr;
535: break;
536:
537: case ONMOUSEDOWN:
538: if (expr != null && expr.isLiteralText()) {
539: _onmousedown = Util.evalString(expr);
540: return;
541: } else
542: _onmousedownExpr = expr;
543: break;
544:
545: case ONMOUSEMOVE:
546: if (expr != null && expr.isLiteralText()) {
547: _onmousemove = Util.evalString(expr);
548: return;
549: } else
550: _onmousemoveExpr = expr;
551: break;
552:
553: case ONMOUSEOUT:
554: if (expr != null && expr.isLiteralText()) {
555: _onmouseout = Util.evalString(expr);
556: return;
557: } else
558: _onmouseoutExpr = expr;
559: break;
560:
561: case ONMOUSEOVER:
562: if (expr != null && expr.isLiteralText()) {
563: _onmouseover = Util.evalString(expr);
564: return;
565: } else
566: _onmouseoverExpr = expr;
567: break;
568:
569: case ONMOUSEUP:
570: if (expr != null && expr.isLiteralText()) {
571: _onmouseup = Util.evalString(expr);
572: return;
573: } else
574: _onmouseupExpr = expr;
575: break;
576:
577: case ONRESET:
578: if (expr != null && expr.isLiteralText()) {
579: _onreset = Util.evalString(expr);
580: return;
581: } else
582: _onresetExpr = expr;
583: break;
584:
585: case ONSUBMIT:
586: if (expr != null && expr.isLiteralText()) {
587: _onsubmit = Util.evalString(expr);
588: return;
589: } else
590: _onsubmitExpr = expr;
591: break;
592:
593: case STYLE:
594: if (expr != null && expr.isLiteralText()) {
595: _style = Util.evalString(expr);
596: return;
597: } else
598: _styleExpr = expr;
599: break;
600:
601: case STYLE_CLASS:
602: if (expr != null && expr.isLiteralText()) {
603: _styleClass = Util.evalString(expr);
604: return;
605: } else
606: _styleClassExpr = expr;
607: break;
608:
609: case TARGET:
610: if (expr != null && expr.isLiteralText()) {
611: _target = Util.evalString(expr);
612: return;
613: } else
614: _targetExpr = expr;
615: break;
616:
617: case TITLE:
618: if (expr != null && expr.isLiteralText()) {
619: _title = Util.evalString(expr);
620: return;
621: } else
622: _titleExpr = expr;
623: break;
624: }
625: }
626:
627: super .setValueExpression(name, expr);
628: }
629:
630: //
631: // state
632: //
633:
634: public Object saveState(FacesContext context) {
635: Object parent = super .saveState(context);
636:
637: return new Object[] { parent, _accept, _acceptcharset, _dir,
638: _enctype, _lang,
639:
640: _onclick, _ondblclick, _onkeydown, _onkeypress,
641: _onkeyup,
642:
643: _onmousedown, _onmousemove, _onmouseout, _onmouseover,
644: _onmouseup,
645:
646: _onreset, _onsubmit,
647:
648: _style, _styleClass, _target, _title, };
649: }
650:
651: public void restoreState(FacesContext context, Object value) {
652: Object[] state = (Object[]) value;
653:
654: int i = 0;
655:
656: if (state != null)
657: super .restoreState(context, state[i++]);
658:
659: _accept = (String) state[i++];
660: _acceptcharset = (String) state[i++];
661: _dir = (String) state[i++];
662: _enctype = (String) state[i++];
663: _lang = (String) state[i++];
664: _onclick = (String) state[i++];
665: _ondblclick = (String) state[i++];
666: _onkeydown = (String) state[i++];
667: _onkeypress = (String) state[i++];
668: _onkeyup = (String) state[i++];
669: _onmousedown = (String) state[i++];
670: _onmousemove = (String) state[i++];
671: _onmouseout = (String) state[i++];
672: _onmouseover = (String) state[i++];
673: _onmouseup = (String) state[i++];
674: _onreset = (String) state[i++];
675: _onsubmit = (String) state[i++];
676: _style = (String) state[i++];
677: _styleClass = (String) state[i++];
678: _target = (String) state[i++];
679: _title = (String) state[i++];
680: }
681:
682: //
683: // utility
684: //
685:
686: private enum PropEnum {
687: ACCEPT, ACCEPTCHARSET, DIR, ENCTYPE, LANG, ONCLICK, ONDBLCLICK, ONKEYDOWN, ONKEYPRESS, ONKEYUP, ONMOUSEDOWN, ONMOUSEMOVE, ONMOUSEOUT, ONMOUSEOVER, ONMOUSEUP, ONRESET, ONSUBMIT, STYLE, STYLE_CLASS, TARGET, TITLE,
688: }
689:
690: static {
691: _propMap.put("accept", PropEnum.ACCEPT);
692: _propMap.put("acceptcharset", PropEnum.ACCEPTCHARSET);
693: _propMap.put("dir", PropEnum.DIR);
694: _propMap.put("enctype", PropEnum.ENCTYPE);
695: _propMap.put("lang", PropEnum.LANG);
696: _propMap.put("onclick", PropEnum.ONCLICK);
697: _propMap.put("ondblclick", PropEnum.ONDBLCLICK);
698: _propMap.put("onkeydown", PropEnum.ONKEYDOWN);
699: _propMap.put("onkeypress", PropEnum.ONKEYPRESS);
700: _propMap.put("onkeyup", PropEnum.ONKEYUP);
701: _propMap.put("onmousedown", PropEnum.ONMOUSEDOWN);
702: _propMap.put("onmousemove", PropEnum.ONMOUSEMOVE);
703: _propMap.put("onmouseover", PropEnum.ONMOUSEOVER);
704: _propMap.put("onmouseout", PropEnum.ONMOUSEOUT);
705: _propMap.put("onmouseup", PropEnum.ONMOUSEUP);
706: _propMap.put("onreset", PropEnum.ONRESET);
707: _propMap.put("onsubmit", PropEnum.ONSUBMIT);
708: _propMap.put("style", PropEnum.STYLE);
709: _propMap.put("styleClass", PropEnum.STYLE_CLASS);
710: _propMap.put("target", PropEnum.TARGET);
711: _propMap.put("title", PropEnum.TITLE);
712: }
713: }
|