KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > ext > HtmlCommandLink


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.ext;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.ext.taglib.Util;
38 import com.icesoft.faces.context.BridgeFacesContext;
39 import com.icesoft.faces.context.effects.CurrentStyle;
40 import com.icesoft.faces.context.effects.Effect;
41 import com.icesoft.faces.context.effects.JavascriptContext;
42
43 import javax.faces.context.FacesContext;
44 import javax.faces.el.ValueBinding;
45
46 /**
47  * This is an extension of javax.faces.component.html.HtmlCommandLink, which
48  * provides some additional behavior to this component such as: <ul> <li>default
49  * classes for enabled and disabled state</li> <li>provides full and partial
50  * submit mechanism</li> <li>changes the component's enabled and rendered state
51  * based on the authentication</li> <li>adds effects to the component</li> <ul>
52  */

53 public class HtmlCommandLink
54         extends javax.faces.component.html.HtmlCommandLink {
55
56     /**
57      * String constant component type
58      */

59     public static final String JavaDoc COMPONENT_TYPE =
60             "com.icesoft.faces.HtmlCommandLink";
61     /**
62      * String constant renderer type
63      */

64     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Link";
65     private String JavaDoc enabledOnUserRole = null;
66     private String JavaDoc renderedOnUserRole = null;
67     private Effect effect;
68     private Boolean JavaDoc visible = null;
69     private Boolean JavaDoc disabled = null;
70     private static final boolean DEFAULT_VISIBLE = true;
71     private Boolean JavaDoc partialSubmit = null;
72
73     private String JavaDoc styleClass = null;
74     private Effect onclickeffect;
75     private Effect ondblclickeffect;
76     private Effect onmousedowneffect;
77     private Effect onmouseupeffect;
78     private Effect onmousemoveeffect;
79     private Effect onmouseovereffect;
80     private Effect onmouseouteffect;
81     private Effect onkeypresseffect;
82     private Effect onkeydowneffect;
83     private Effect onkeyupeffect;
84
85     private boolean focus = false;
86
87     private CurrentStyle currentStyle;
88
89     /**
90      * default no args constructor
91      */

92     public HtmlCommandLink() {
93         super();
94         setRendererType(RENDERER_TYPE);
95     }
96
97     /**
98      * This method is used to communicate a focus request from the application
99      * to the client browser.
100      */

101     public void requestFocus() {
102         ((BridgeFacesContext) FacesContext.getCurrentInstance())
103                 .setFocusId("null");
104         JavascriptContext.focus(FacesContext.getCurrentInstance(),
105                                 this.getClientId(
106                                         FacesContext.getCurrentInstance()));
107     }
108
109     /**
110      * @param focus
111      */

112     public void setFocus(boolean focus) {
113         this.focus = focus;
114     }
115
116     /**
117      * @return boolean focus
118      */

119     public boolean isFocus() {
120         return this.focus;
121     }
122
123     /* (non-Javadoc)
124      * @see javax.faces.component.UIComponentBase#setValueBinding(java.lang.String, javax.faces.el.ValueBinding)
125      */

126     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
127         if (s != null && s.indexOf("effect") != -1) {
128             // If this is an effect attribute make sure Ice Extras is included
129
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
130                                          getFacesContext());
131         }
132         super.setValueBinding(s, vb);
133     }
134
135     /**
136      * <p>Set the value of the <code>partialSubmit</code> property.</p>
137      *
138      * @param partialSubmit
139      */

140     public void setPartialSubmit(boolean partialSubmit) {
141         this.partialSubmit = Boolean.valueOf(partialSubmit);
142     }
143
144     /**
145      * <p>Return the value of the <code>partialSubmit</code> property.</p>
146      *
147      * @return boolean partialSubmit
148      */

149     public boolean getPartialSubmit() {
150         if (partialSubmit != null) {
151             return partialSubmit.booleanValue();
152         }
153         ValueBinding vb = getValueBinding("partialSubmit");
154         Boolean JavaDoc boolVal =
155                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
156         return boolVal != null ? boolVal.booleanValue() :
157                Util.isParentPartialSubmit(this);
158     }
159
160     /**
161      * <p>Set the value of the <code>styleClass</code> property.</p>
162      *
163      * @param styleClass
164      */

165     public void setStyleClass(String JavaDoc styleClass) {
166         this.styleClass = styleClass;
167     }
168
169     /**
170      * <p>Return the value of the <code>styleClass</code> property.</p>
171      *
172      * @return String styleClass
173      */

174     public String JavaDoc getStyleClass() {
175         return Util.getQualifiedStyleClass(this,
176                 styleClass,
177                 CSS_DEFAULT.COMMAND_LINK_DEFAULT_STYLE_CLASS,
178                 "styleClass",
179                 isDisabled());
180                                              
181     }
182
183     /**
184      * <p>Set the value of the <code>visible</code> property.</p>
185      *
186      * @param visible
187      */

188     public void setVisible(boolean visible) {
189         this.visible = Boolean.valueOf(visible);
190     }
191
192     /**
193      * <p>Return the value of the <code>visible</code> property.</p>
194      *
195      * @return boolean visible
196      */

197     public boolean isVisible() {
198         if (visible != null) {
199             return visible.booleanValue();
200         }
201         ValueBinding vb = getValueBinding("visible");
202         Boolean JavaDoc boolVal =
203                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
204         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
205     }
206
207     /**
208      * <p>Return the value of the <code>visible</code> property.</p>
209      *
210      * @return boolean visible
211      */

212     public boolean getVisible() {
213         if (visible != null) {
214             return visible.booleanValue();
215         }
216         ValueBinding vb = getValueBinding("visible");
217         Boolean JavaDoc boolVal =
218                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
219         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
220     }
221
222     /**
223      * <p>Set the value of the <code>effect</code> property.</p>
224      *
225      * @param effect
226      */

227     public void setEffect(Effect effect) {
228         JavascriptContext
229                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
230         this.effect = effect;
231     }
232
233     /**
234      * <p>Return the value of the <code>effect</code> property.</p>
235      *
236      * @return Effect
237      */

238     public Effect getEffect() {
239         if (effect != null) {
240             return effect;
241         }
242         ValueBinding vb = getValueBinding("effect");
243         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
244     }
245
246     /**
247      * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
248      *
249      * @param enabledOnUserRole
250      */

251     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
252         this.enabledOnUserRole = enabledOnUserRole;
253     }
254
255     /**
256      * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
257      *
258      * @return String enabledOnUserRole
259      */

260     public String JavaDoc getEnabledOnUserRole() {
261         if (enabledOnUserRole != null) {
262             return enabledOnUserRole;
263         }
264         ValueBinding vb = getValueBinding("enabledOnUserRole");
265         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
266     }
267
268     /**
269      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
270      *
271      * @param renderedOnUserRole
272      */

273     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
274         this.renderedOnUserRole = renderedOnUserRole;
275     }
276
277     /**
278      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
279      *
280      * @return String renderedOnUserRole
281      */

282     public String JavaDoc getRenderedOnUserRole() {
283         if (renderedOnUserRole != null) {
284             return renderedOnUserRole;
285         }
286         ValueBinding vb = getValueBinding("renderedOnUserRole");
287         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
288     }
289
290     /**
291      * <p>Return the value of the <code>rendered</code> property.</p>
292      *
293      * @return boolean rendered
294      */

295     public boolean isRendered() {
296         if (!Util.isRenderedOnUserRole(this)) {
297             return false;
298         }
299         return super.isRendered();
300     }
301
302     /**
303      * <p>Set the value of the <code>disabled</code> property.</p>
304      *
305      * @param disabled
306      */

307     public void setDisabled(boolean disabled) {
308         this.disabled = new Boolean JavaDoc(disabled);
309         ValueBinding vb = getValueBinding("disabled");
310         if (vb != null) {
311             vb.setValue(getFacesContext(), this.disabled);
312             this.disabled = null;
313         }
314     }
315
316     /**
317      * <p>Return the value of the <code>disabled</code> property.</p>
318      *
319      * @return boolean disabled
320      */

321     public boolean isDisabled() {
322         if (!Util.isEnabledOnUserRole(this)) {
323             return true;
324         }
325
326         if (disabled != null) {
327             return disabled.booleanValue();
328         }
329         ValueBinding vb = getValueBinding("disabled");
330         Boolean JavaDoc v =
331                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
332         return v != null ? v.booleanValue() : false;
333     }
334
335     /**
336      * <p>Return the value of the <code>onclickeffect</code> property.</p>
337      *
338      * @return Effect
339      */

340     public Effect getOnclickeffect() {
341         if (onclickeffect != null) {
342             return onclickeffect;
343         }
344         ValueBinding vb = getValueBinding("onclickeffect");
345
346         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
347     }
348
349     /**
350      * <p>Set the value of the <code>onclickeffect</code> property.</p>
351      *
352      * @param onclickeffect
353      */

354     public void setOnclickeffect(Effect onclickeffect) {
355         JavascriptContext
356                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
357         this.onclickeffect = onclickeffect;
358     }
359
360     /**
361      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
362      *
363      * @return Effect
364      */

365     public Effect getOndblclickeffect() {
366         if (ondblclickeffect != null) {
367             return ondblclickeffect;
368         }
369         ValueBinding vb = getValueBinding("ondblclickeffect");
370
371         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
372     }
373
374     /**
375      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
376      *
377      * @param ondblclickeffect
378      */

379     public void setOndblclickeffect(Effect ondblclickeffect) {
380         JavascriptContext
381                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
382         this.ondblclickeffect = ondblclickeffect;
383     }
384
385     /**
386      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
387      *
388      * @return Effect
389      */

390     public Effect getOnmousedowneffect() {
391         if (onmousedowneffect != null) {
392             return onmousedowneffect;
393         }
394         ValueBinding vb = getValueBinding("onmousedowneffect");
395
396         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
397     }
398
399     /**
400      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
401      *
402      * @param onmousedowneffect
403      */

404     public void setOnmousedowneffect(Effect onmousedowneffect) {
405         JavascriptContext
406                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
407         this.onmousedowneffect = onmousedowneffect;
408     }
409
410     /**
411      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
412      *
413      * @return Effect
414      */

415     public Effect getOnmouseupeffect() {
416         if (onmouseupeffect != null) {
417             return onmouseupeffect;
418         }
419         ValueBinding vb = getValueBinding("onmouseupeffect");
420
421         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
422     }
423
424     /**
425      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
426      *
427      * @param onmouseupeffect
428      */

429     public void setOnmouseupeffect(Effect onmouseupeffect) {
430         JavascriptContext
431                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
432         this.onmouseupeffect = onmouseupeffect;
433     }
434
435     /**
436      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
437      *
438      * @return Effect
439      */

440     public Effect getOnmousemoveeffect() {
441         if (onmousemoveeffect != null) {
442             return onmousemoveeffect;
443         }
444         ValueBinding vb = getValueBinding("onmousemoveeffect");
445
446         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
447     }
448
449     /**
450      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
451      *
452      * @param onmousemoveeffect
453      */

454     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
455         JavascriptContext
456                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
457         this.onmousemoveeffect = onmousemoveeffect;
458     }
459
460     /**
461      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
462      *
463      * @return Effect
464      */

465     public Effect getOnmouseovereffect() {
466         if (onmouseovereffect != null) {
467             return onmouseovereffect;
468         }
469         ValueBinding vb = getValueBinding("onmouseovereffect");
470
471         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
472     }
473
474     /**
475      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
476      *
477      * @param onmouseovereffect
478      */

479     public void setOnmouseovereffect(Effect onmouseovereffect) {
480         JavascriptContext
481                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
482         this.onmouseovereffect = onmouseovereffect;
483     }
484
485     /**
486      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
487      *
488      * @return Effect
489      */

490     public Effect getOnmouseouteffect() {
491         if (onmouseouteffect != null) {
492             return onmouseouteffect;
493         }
494         ValueBinding vb = getValueBinding("onmouseouteffect");
495
496         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
497     }
498
499     /**
500      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
501      *
502      * @param onmouseouteffect
503      */

504     public void setOnmouseouteffect(Effect onmouseouteffect) {
505         JavascriptContext
506                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
507         this.onmouseouteffect = onmouseouteffect;
508     }
509
510
511     /**
512      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
513      *
514      * @return Effect
515      */

516     public Effect getOnkeypresseffect() {
517         if (onkeypresseffect != null) {
518             return onkeypresseffect;
519         }
520         ValueBinding vb = getValueBinding("onkeypresseffect");
521
522         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
523     }
524
525     /**
526      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
527      *
528      * @param onkeypresseffect
529      */

530     public void setOnkeypresseffect(Effect onkeypresseffect) {
531         JavascriptContext
532                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
533         this.onkeypresseffect = onkeypresseffect;
534     }
535
536     /**
537      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
538      *
539      * @return Effect
540      */

541     public Effect getOnkeydowneffect() {
542         if (onkeydowneffect != null) {
543             return onkeydowneffect;
544         }
545         ValueBinding vb = getValueBinding("onkeydowneffect");
546
547         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
548     }
549
550     /**
551      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
552      *
553      * @param onkeydowneffect
554      */

555     public void setOnkeydowneffect(Effect onkeydowneffect) {
556         JavascriptContext
557                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
558         this.onkeydowneffect = onkeydowneffect;
559     }
560
561     /**
562      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
563      *
564      * @return Effect
565      */

566     public Effect getOnkeyupeffect() {
567         if (onkeyupeffect != null) {
568             return onkeyupeffect;
569         }
570         ValueBinding vb = getValueBinding("onkeyupeffect");
571
572         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
573     }
574
575     /**
576      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
577      *
578      * @param onkeyupeffect
579      */

580     public void setOnkeyupeffect(Effect onkeyupeffect) {
581         JavascriptContext
582                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
583         this.onkeyupeffect = onkeyupeffect;
584     }
585
586     /**
587      * <p>Return the value of the <code>currentStyle</code> property.</p>
588      *
589      * @return CurrentStyle
590      */

591     public CurrentStyle getCurrentStyle() {
592         return currentStyle;
593     }
594
595     /**
596      * <p>Set the value of the <code>currentStyle</code> property.</p>
597      *
598      * @param currentStyle
599      */

600     public void setCurrentStyle(CurrentStyle currentStyle) {
601         this.currentStyle = currentStyle;
602     }
603
604
605     /**
606      * <p>Gets the state of the instance as a <code>Serializable</code>
607      * Object.</p>
608      *
609      * @param context
610      * @return Object values[]
611      */

612     public Object JavaDoc saveState(FacesContext context) {
613         Object JavaDoc values[] = new Object JavaDoc[20];
614         values[0] = super.saveState(context);
615         values[1] = enabledOnUserRole;
616         values[2] = renderedOnUserRole;
617         values[3] = effect;
618         values[4] = onclickeffect;
619         values[5] = ondblclickeffect;
620         values[6] = onmousedowneffect;
621         values[7] = onmouseupeffect;
622         values[8] = onmousemoveeffect;
623         values[9] = onmouseovereffect;
624         values[10] = onmouseouteffect;
625         values[14] = onkeypresseffect;
626         values[15] = onkeydowneffect;
627         values[16] = onkeyupeffect;
628         values[17] = currentStyle;
629         values[18] = visible;
630         values[19] = styleClass;
631         return ((Object JavaDoc) (values));
632     }
633
634     /**
635      * <p>Perform any processing required to restore the state from the entries
636      * in the state Object.</p>
637      *
638      * @param context
639      * @param state
640      */

641     public void restoreState(FacesContext context, Object JavaDoc state) {
642         Object JavaDoc values[] = (Object JavaDoc[]) state;
643         super.restoreState(context, values[0]);
644         enabledOnUserRole = (String JavaDoc) values[1];
645         renderedOnUserRole = (String JavaDoc) values[2];
646         effect = (Effect) values[3];
647         onclickeffect = (Effect) values[4];
648         ondblclickeffect = (Effect) values[5];
649         onmousedowneffect = (Effect) values[6];
650         onmouseupeffect = (Effect) values[7];
651         onmousemoveeffect = (Effect) values[8];
652         onmouseovereffect = (Effect) values[9];
653         onmouseouteffect = (Effect) values[10];
654         onkeypresseffect = (Effect) values[14];
655         onkeydowneffect = (Effect) values[15];
656         onkeyupeffect = (Effect) values[16];
657         currentStyle = (CurrentStyle) values[17];
658         visible = (Boolean JavaDoc) values[18];
659         styleClass = (String JavaDoc) values[19];
660     }
661 }
662    
663
664   
Popular Tags