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.ext.taglib.Util;
038: import com.icesoft.faces.context.BridgeFacesContext;
039: import com.icesoft.faces.context.effects.CurrentStyle;
040: import com.icesoft.faces.context.effects.Effect;
041: import com.icesoft.faces.context.effects.JavascriptContext;
042:
043: import javax.faces.context.FacesContext;
044: import javax.faces.el.ValueBinding;
045:
046: /**
047: * This is an extension of com.icesoft.faces.component.ext.HtmlInputText, which
048: * provides some additional behavior to this component such as: <ul> <li>default
049: * classes for enabled and disabled state</li> <li>provides full and partial
050: * submit mechanism</li> <li>changes the component's enabled and rendered state
051: * based on the authentication</li> <li>adds effects to the component</li>
052: * <li>allows to set the action and actionListener for this component</li> <ul>
053: */
054: public class HtmlInputSecret extends HtmlInputText {
055: public static final String COMPONENT_TYPE = "com.icesoft.faces.HtmlInputSecret";
056: public static final String RENDERER_TYPE = "com.icesoft.faces.Secret";
057: private static final boolean DEFAULT_VISIBLE = true;
058: private String styleClass = null;
059: private boolean redisplay = false;
060: private boolean redisplaySet = false;
061: private boolean focus = false;
062:
063: private Effect onclickeffect;
064: private Effect ondblclickeffect;
065: private Effect onmousedowneffect;
066: private Effect onmouseupeffect;
067: private Effect onmousemoveeffect;
068: private Effect onmouseovereffect;
069: private Effect onmouseouteffect;
070: private Effect onchangeeffect;
071: private Effect onkeypresseffect;
072: private Effect onkeydowneffect;
073: private Effect onkeyupeffect;
074:
075: private CurrentStyle currentStyle;
076:
077: private Effect effect;
078: private Boolean visible = null;
079:
080: public HtmlInputSecret() {
081: super ();
082: setRendererType(RENDERER_TYPE);
083: }
084:
085: /**
086: * This method is used to communicate a focus request from the application
087: * to the client browser.
088: */
089: public void requestFocus() {
090: ((BridgeFacesContext) FacesContext.getCurrentInstance())
091: .setFocusId("null");
092: JavascriptContext.focus(FacesContext.getCurrentInstance(), this
093: .getClientId(FacesContext.getCurrentInstance()));
094: }
095:
096: public void setValueBinding(String s, ValueBinding vb) {
097: if (s != null && s.indexOf("effect") != -1) {
098: // If this is an effect attribute make sure Ice Extras is included
099: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
100: getFacesContext());
101: }
102: super .setValueBinding(s, vb);
103: }
104:
105: /**
106: * <p>Set the value of the <code>effect</code> property.</p>
107: */
108: public void setEffect(Effect effect) {
109: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
110: getFacesContext());
111: this .effect = effect;
112: }
113:
114: /**
115: * <p>Return the value of the <code>effect</code> property.</p>
116: */
117: public Effect getEffect() {
118: if (effect != null) {
119: return effect;
120: }
121: ValueBinding vb = getValueBinding("effect");
122: return vb != null ? (Effect) vb.getValue(getFacesContext())
123: : null;
124: }
125:
126: /**
127: * <p>Set the value of the <code>visible</code> property.</p>
128: */
129: public void setVisible(boolean visible) {
130: this .visible = Boolean.valueOf(visible);
131: }
132:
133: /**
134: * <p>Return the value of the <code>visible</code> property.</p>
135: */
136: public boolean getVisible() {
137: if (visible != null) {
138: return visible.booleanValue();
139: }
140: ValueBinding vb = getValueBinding("visible");
141: Boolean boolVal = vb != null ? (Boolean) vb
142: .getValue(getFacesContext()) : null;
143: return boolVal != null ? boolVal.booleanValue()
144: : DEFAULT_VISIBLE;
145: }
146:
147: /**
148: * <p>Set the value of the <code>styleClass</code> property.</p>
149: */
150: public void setStyleClass(String styleClass) {
151: this .styleClass = styleClass;
152: }
153:
154: /**
155: * <p>Return the value of the <code>styleClass</code> property.</p>
156: */
157: public String getStyleClass() {
158: return Util.getQualifiedStyleClass(this , styleClass,
159: CSS_DEFAULT.INPUT_SECRET_DEFAULT_STYLE_CLASS,
160: "styleClass", isDisabled());
161:
162: }
163:
164: /**
165: * <p>Return the value of the <code>rendered</code> property.</p>
166: */
167: public boolean isRendered() {
168: if (!Util.isRenderedOnUserRole(this )) {
169: return false;
170: }
171: return super .isRendered();
172: }
173:
174: /**
175: * <p>Set the value of the <code>redisplay</code> property.</p>
176: */
177: public void setRedisplay(boolean redisplay) {
178: this .redisplay = redisplay;
179: }
180:
181: /**
182: * <p>Return the value of the <code>redisplay</code> property.</p>
183: */
184: public boolean isRedisplay() {
185: if (this .redisplaySet) {
186: return this .redisplay;
187: }
188: ValueBinding _vb = getValueBinding("redisplay");
189: if (_vb != null) {
190: Object _result = _vb.getValue(getFacesContext());
191: if (_result == null) {
192: return false;
193: } else {
194: return ((Boolean) _result).booleanValue();
195: }
196: } else {
197: return this .redisplay;
198: }
199: }
200:
201: /**
202: * <p>Set the value of the <code>focus</code> property.</p>
203: */
204: public void setFocus(boolean focus) {
205: this .focus = focus;
206: }
207:
208: /**
209: * <p>Return the value of the <code>focus</code> property.</p>
210: */
211: public boolean hasFocus() {
212: return focus;
213: }
214:
215: /**
216: * <p>Return the value of the <code>onclickeffect</code> property.</p>
217: */
218: public Effect getOnclickeffect() {
219: if (onclickeffect != null) {
220: return onclickeffect;
221: }
222: ValueBinding vb = getValueBinding("onclickeffect");
223:
224: return vb != null ? (Effect) vb.getValue(getFacesContext())
225: : null;
226: }
227:
228: /**
229: * <p>Set the value of the <code>onclickeffect</code> property.</p>
230: */
231: public void setOnclickeffect(Effect onclickeffect) {
232: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
233: getFacesContext());
234: this .onclickeffect = onclickeffect;
235: }
236:
237: /**
238: * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
239: */
240: public Effect getOndblclickeffect() {
241: if (ondblclickeffect != null) {
242: return ondblclickeffect;
243: }
244: ValueBinding vb = getValueBinding("ondblclickeffect");
245:
246: return vb != null ? (Effect) vb.getValue(getFacesContext())
247: : null;
248: }
249:
250: /**
251: * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
252: */
253: public void setOndblclickeffect(Effect ondblclickeffect) {
254: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
255: getFacesContext());
256: this .ondblclickeffect = ondblclickeffect;
257: }
258:
259: /**
260: * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
261: */
262: public Effect getOnmousedowneffect() {
263: if (onmousedowneffect != null) {
264: return onmousedowneffect;
265: }
266: ValueBinding vb = getValueBinding("onmousedowneffect");
267:
268: return vb != null ? (Effect) vb.getValue(getFacesContext())
269: : null;
270: }
271:
272: /**
273: * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
274: */
275: public void setOnmousedowneffect(Effect onmousedowneffect) {
276: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
277: getFacesContext());
278: this .onmousedowneffect = onmousedowneffect;
279: }
280:
281: /**
282: * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
283: */
284: public Effect getOnmouseupeffect() {
285: if (onmouseupeffect != null) {
286: return onmouseupeffect;
287: }
288: ValueBinding vb = getValueBinding("onmouseupeffect");
289:
290: return vb != null ? (Effect) vb.getValue(getFacesContext())
291: : null;
292: }
293:
294: /**
295: * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
296: */
297: public void setOnmouseupeffect(Effect onmouseupeffect) {
298: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
299: getFacesContext());
300: this .onmouseupeffect = onmouseupeffect;
301: }
302:
303: /**
304: * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
305: */
306: public Effect getOnmousemoveeffect() {
307: if (onmousemoveeffect != null) {
308: return onmousemoveeffect;
309: }
310: ValueBinding vb = getValueBinding("onmousemoveeffect");
311:
312: return vb != null ? (Effect) vb.getValue(getFacesContext())
313: : null;
314: }
315:
316: /**
317: * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
318: */
319: public void setOnmousemoveeffect(Effect onmousemoveeffect) {
320: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
321: getFacesContext());
322: this .onmousemoveeffect = onmousemoveeffect;
323: }
324:
325: /**
326: * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
327: */
328: public Effect getOnmouseovereffect() {
329: if (onmouseovereffect != null) {
330: return onmouseovereffect;
331: }
332: ValueBinding vb = getValueBinding("onmouseovereffect");
333:
334: return vb != null ? (Effect) vb.getValue(getFacesContext())
335: : null;
336: }
337:
338: /**
339: * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
340: */
341: public void setOnmouseovereffect(Effect onmouseovereffect) {
342: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
343: getFacesContext());
344: this .onmouseovereffect = onmouseovereffect;
345: }
346:
347: /**
348: * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
349: */
350: public Effect getOnmouseouteffect() {
351: if (onmouseouteffect != null) {
352: return onmouseouteffect;
353: }
354: ValueBinding vb = getValueBinding("onmouseouteffect");
355:
356: return vb != null ? (Effect) vb.getValue(getFacesContext())
357: : null;
358: }
359:
360: /**
361: * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
362: */
363: public void setOnmouseouteffect(Effect onmouseouteffect) {
364: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
365: getFacesContext());
366: this .onmouseouteffect = onmouseouteffect;
367: }
368:
369: /**
370: * <p>Return the value of the <code>onchangeeffect</code> property.</p>
371: */
372: public Effect getOnchangeeffect() {
373: if (onchangeeffect != null) {
374: return onchangeeffect;
375: }
376: ValueBinding vb = getValueBinding("onchangeeffect");
377:
378: return vb != null ? (Effect) vb.getValue(getFacesContext())
379: : null;
380: }
381:
382: /**
383: * <p>Set the value of the <code>onchangeeffect</code> property.</p>
384: */
385: public void setOnchangeeffect(Effect onchangeeffect) {
386: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
387: getFacesContext());
388: this .onchangeeffect = onchangeeffect;
389: }
390:
391: /**
392: * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
393: */
394: public Effect getOnkeypresseffect() {
395: if (onkeypresseffect != null) {
396: return onkeypresseffect;
397: }
398: ValueBinding vb = getValueBinding("onkeypresseffect");
399:
400: return vb != null ? (Effect) vb.getValue(getFacesContext())
401: : null;
402: }
403:
404: /**
405: * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
406: */
407: public void setOnkeypresseffect(Effect onkeypresseffect) {
408: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
409: getFacesContext());
410: this .onkeypresseffect = onkeypresseffect;
411: }
412:
413: /**
414: * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
415: */
416: public Effect getOnkeydowneffect() {
417: if (onkeydowneffect != null) {
418: return onkeydowneffect;
419: }
420: ValueBinding vb = getValueBinding("onkeydowneffect");
421:
422: return vb != null ? (Effect) vb.getValue(getFacesContext())
423: : null;
424: }
425:
426: /**
427: * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
428: */
429: public void setOnkeydowneffect(Effect onkeydowneffect) {
430: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
431: getFacesContext());
432: this .onkeydowneffect = onkeydowneffect;
433: }
434:
435: /**
436: * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
437: */
438: public Effect getOnkeyupeffect() {
439: if (onkeyupeffect != null) {
440: return onkeyupeffect;
441: }
442: ValueBinding vb = getValueBinding("onkeyupeffect");
443:
444: return vb != null ? (Effect) vb.getValue(getFacesContext())
445: : null;
446: }
447:
448: /**
449: * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
450: */
451: public void setOnkeyupeffect(Effect onkeyupeffect) {
452: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
453: getFacesContext());
454: this .onkeyupeffect = onkeyupeffect;
455: }
456:
457: /**
458: * <p>Return the value of the <code>currentStyle</code> property.</p>
459: */
460: public CurrentStyle getCurrentStyle() {
461: return currentStyle;
462: }
463:
464: /**
465: * <p>Set the value of the <code>currentStyle</code> property.</p>
466: */
467: public void setCurrentStyle(CurrentStyle currentStyle) {
468: this .currentStyle = currentStyle;
469: }
470:
471: private String autocomplete;
472:
473: /**
474: * <p>Set the value of the <code>autocomplete</code> property.</p>
475: */
476: public void setAutocomplete(String autocomplete) {
477: this .autocomplete = autocomplete;
478: }
479:
480: /**
481: * <p>Return the value of the <code>autocomplete</code> property.</p>
482: */
483: public String getAutocomplete() {
484: if (autocomplete != null) {
485: return autocomplete;
486: }
487: ValueBinding vb = getValueBinding("autocomplete");
488: return vb != null ? (String) vb.getValue(getFacesContext())
489: : null;
490: }
491:
492: /**
493: * <p>Gets the state of the instance as a <code>Serializable</code>
494: * Object.</p>
495: */
496: public Object saveState(FacesContext context) {
497: Object values[] = new Object[21];
498: values[0] = super .saveState(context);
499: values[1] = onkeyupeffect;
500: values[2] = styleClass;
501: values[3] = redisplay ? Boolean.TRUE : Boolean.FALSE;
502: values[4] = redisplaySet ? Boolean.TRUE : Boolean.FALSE;
503: values[5] = onclickeffect;
504: values[6] = ondblclickeffect;
505: values[7] = onmousedowneffect;
506: values[8] = onmouseupeffect;
507: values[9] = onmousemoveeffect;
508: values[10] = onmouseovereffect;
509: values[11] = onmouseouteffect;
510: values[12] = onchangeeffect;
511: values[15] = onkeypresseffect;
512: values[16] = onkeydowneffect;
513: values[17] = currentStyle;
514: values[18] = effect;
515: values[19] = visible;
516: values[20] = autocomplete;
517: return ((Object) (values));
518: }
519:
520: /**
521: * <p>Perform any processing required to restore the state from the entries
522: * in the state Object.</p>
523: */
524: public void restoreState(FacesContext context, Object state) {
525: Object values[] = (Object[]) state;
526: super .restoreState(context, values[0]);
527: onkeyupeffect = (Effect) values[1];
528: styleClass = (String) values[2];
529: redisplay = ((Boolean) values[3]).booleanValue();
530: redisplaySet = ((Boolean) values[3]).booleanValue();
531: onclickeffect = (Effect) values[5];
532: ondblclickeffect = (Effect) values[6];
533: onmousedowneffect = (Effect) values[7];
534: onmouseupeffect = (Effect) values[8];
535: onmousemoveeffect = (Effect) values[9];
536: onmouseovereffect = (Effect) values[10];
537: onmouseouteffect = (Effect) values[11];
538: onchangeeffect = (Effect) values[12];
539: onkeypresseffect = (Effect) values[15];
540: onkeydowneffect = (Effect) values[16];
541: currentStyle = (CurrentStyle) values[17];
542: effect = (Effect) values[18];
543: visible = (Boolean) values[19];
544: autocomplete = (String) values[20];
545: }
546: }
|