KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
48  * This is an extension of javax.faces.component.html.HtmlCommandButton, which
49  * provides some additional behavior to this component such as: <ul> <li>default
50  * classes for enabled and disabled state</li> <li>provides full and partial
51  * submit mechanism</li> <li>changes the component's enabled and rendered state
52  * based on the authentication</li> <li>adds effects to the component</li> <ul>
53  */

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

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

65     public static final String JavaDoc RENDERER_TYPE = "com.icesoft.faces.Button";
66     private String JavaDoc styleClass = null;
67     private String JavaDoc enabledOnUserRole = null;
68     private String JavaDoc renderedOnUserRole = null;
69     private Effect effect = null;
70     private Boolean JavaDoc visible = null;
71     private static final boolean DEFAULT_VISIBLE = true;
72     private Boolean JavaDoc partialSubmit = null;
73
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 onchangeeffect;
82
//private Effect onreseteffect;
83
//private Effect onsubmiteffect;
84
private Effect onkeypresseffect;
85     private Effect onkeydowneffect;
86     private Effect onkeyupeffect;
87     private CurrentStyle currentStyle;
88
89     /**
90      * default no args constructor
91      */

92     public HtmlCommandButton() {
93         super();
94         setRendererType(RENDERER_TYPE);
95     }
96
97     /* (non-Javadoc)
98      * @see javax.faces.component.UIComponentBase#setValueBinding(java.lang.String, javax.faces.el.ValueBinding)
99      */

100     public void setValueBinding(String JavaDoc s, ValueBinding vb) {
101         if (s != null && s.indexOf("effect") != -1) {
102             // If this is an effect attribute make sure Ice Extras is included
103
JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
104                                          getFacesContext());
105         }
106         super.setValueBinding(s, vb);
107     }
108
109     /**
110      * <p>Set the value of the <code>dir</code> property.</p>
111      *
112      * @param partialSubmit
113      */

114     public void setPartialSubmit(boolean partialSubmit) {
115         this.partialSubmit = Boolean.valueOf(partialSubmit);
116     }
117
118     /**
119      * <p>Return the value of the <code>partialSubmit</code> property.</p>
120      *
121      * @return boolean partialSubmit
122      */

123     public boolean getPartialSubmit() {
124         if (partialSubmit != null) {
125             return partialSubmit.booleanValue();
126         }
127         ValueBinding vb = getValueBinding("partialSubmit");
128         Boolean JavaDoc boolVal =
129                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
130         return boolVal != null ? boolVal.booleanValue() :
131                Util.isParentPartialSubmit(this);
132     }
133
134     /**
135      * <p>Set the value of the <code>effect</code> property.</p>
136      *
137      * @param effect
138      */

139     public void setEffect(Effect effect) {
140         JavascriptContext
141                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
142         this.effect = effect;
143     }
144
145     /**
146      * <p>Return the value of the <code>effect</code> property.</p>
147      *
148      * @return Effect effect
149      */

150     public Effect getEffect() {
151         if (effect != null) {
152             return effect;
153         }
154         ValueBinding vb = getValueBinding("effect");
155         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
156     }
157
158     /**
159      * <p>Set the value of the <code>visible</code> property.</p>
160      *
161      * @param visible
162      */

163     public void setVisible(boolean visible) {
164         this.visible = Boolean.valueOf(visible);
165     }
166
167     /**
168      * <p>Return the value of the <code>visible</code> property.</p>
169      *
170      * @return boolean visible
171      */

172     public boolean isVisible() {
173         if (visible != null) {
174             return visible.booleanValue();
175         }
176         ValueBinding vb = getValueBinding("visible");
177         Boolean JavaDoc boolVal =
178                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
179         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
180     }
181
182
183     /**
184      * <p>Return the value of the <code>visible</code> property.</p>
185      *
186      * @return boolean visible
187      */

188     public boolean getVisible() {
189         if (visible != null) {
190             return visible.booleanValue();
191         }
192         ValueBinding vb = getValueBinding("visible");
193         Boolean JavaDoc boolVal =
194                 vb != null ? (Boolean JavaDoc) vb.getValue(getFacesContext()) : null;
195         return boolVal != null ? boolVal.booleanValue() : DEFAULT_VISIBLE;
196     }
197
198     /**
199      * <p>Return the value of the <code>disabled</code> property.</p>
200      *
201      * @return boolean disabled
202      */

203     public boolean isDisabled() {
204         if (!Util.isEnabledOnUserRole(this)) {
205             return true;
206         } else {
207             return super.isDisabled();
208         }
209     }
210
211
212     /**
213      * <p>Set the value of the <code>enabledOnUserRole</code> property.</p>
214      *
215      * @param enabledOnUserRole
216      */

217     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole) {
218         this.enabledOnUserRole = enabledOnUserRole;
219     }
220
221     /**
222      * <p>Return the value of the <code>enabledOnUserRole</code> property.</p>
223      *
224      * @return String enabledOnUserRole
225      */

226     public String JavaDoc getEnabledOnUserRole() {
227         if (enabledOnUserRole != null) {
228             return enabledOnUserRole;
229         }
230         ValueBinding vb = getValueBinding("enabledOnUserRole");
231         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
232     }
233
234     /**
235      * <p>Set the value of the <code>renderedOnUserRole</code> property.</p>
236      *
237      * @param renderedOnUserRole
238      */

239     public void setRenderedOnUserRole(String JavaDoc renderedOnUserRole) {
240         this.renderedOnUserRole = renderedOnUserRole;
241     }
242
243     /**
244      * <p>Return the value of the <code>renderedOnUserRole</code> property.</p>
245      *
246      * @return String renderedOnUserRole
247      */

248     public String JavaDoc getRenderedOnUserRole() {
249         if (renderedOnUserRole != null) {
250             return renderedOnUserRole;
251         }
252         ValueBinding vb = getValueBinding("renderedOnUserRole");
253         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
254     }
255
256     /**
257      * <p>Set the value of the <code>styleClass</code> property.</p>
258      *
259      * @param styleClass
260      */

261     public void setStyleClass(String JavaDoc styleClass) {
262         this.styleClass = styleClass;
263     }
264
265     /**
266      * <p>Return the value of the <code>styleClass</code> property.</p>
267      *
268      * @return String styleClass
269      */

270     public String JavaDoc getStyleClass() {
271         return Util.getQualifiedStyleClass(this,
272                                 styleClass,
273                                 CSS_DEFAULT.COMMAND_BTN_DEFAULT_STYLE_CLASS,
274                                 "styleClass",
275                                 isDisabled());
276     }
277
278     /**
279      * <p>Return the value of the <code>rendered</code> property.</p>
280      *
281      * @return boolean rendered
282      */

283     public boolean isRendered() {
284         if (!Util.isRenderedOnUserRole(this)) {
285             return false;
286         }
287         return super.isRendered();
288     }
289
290     /**
291      * <p>Return the value of the <code>onclickeffect</code> property.</p>
292      *
293      * @return Effect onclickEffect
294      */

295     public Effect getOnclickeffect() {
296         if (onclickeffect != null) {
297             return onclickeffect;
298         }
299         ValueBinding vb = getValueBinding("onclickeffect");
300
301         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
302     }
303
304     /**
305      * <p>Set the value of the <code>onclickeffect</code> property.</p>
306      *
307      * @param onclickeffect
308      */

309     public void setOnclickeffect(Effect onclickeffect) {
310         JavascriptContext
311                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
312         this.onclickeffect = onclickeffect;
313     }
314
315     /**
316      * <p>Return the value of the <code>ondblclickeffect</code> property.</p>
317      *
318      * @return Effect
319      */

320     public Effect getOndblclickeffect() {
321         if (ondblclickeffect != null) {
322             return ondblclickeffect;
323         }
324         ValueBinding vb = getValueBinding("ondblclickeffect");
325
326         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
327     }
328
329     /**
330      * <p>Set the value of the <code>ondblclickeffect</code> property.</p>
331      *
332      * @param ondblclickeffect
333      */

334     public void setOndblclickeffect(Effect ondblclickeffect) {
335         JavascriptContext
336                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
337         this.ondblclickeffect = ondblclickeffect;
338     }
339
340     /**
341      * <p>Return the value of the <code>onmousedowneffect</code> property.</p>
342      *
343      * @return Effect
344      */

345     public Effect getOnmousedowneffect() {
346         if (onmousedowneffect != null) {
347             return onmousedowneffect;
348         }
349         ValueBinding vb = getValueBinding("onmousedowneffect");
350
351         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
352     }
353
354     /**
355      * <p>Set the value of the <code>onmousedowneffect</code> property.</p>
356      *
357      * @param onmousedowneffect
358      */

359     public void setOnmousedowneffect(Effect onmousedowneffect) {
360         JavascriptContext
361                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
362         this.onmousedowneffect = onmousedowneffect;
363     }
364
365     /**
366      * <p>Return the value of the <code>onmouseupeffect</code> property.</p>
367      *
368      * @return Effect
369      */

370     public Effect getOnmouseupeffect() {
371         if (onmouseupeffect != null) {
372             return onmouseupeffect;
373         }
374         ValueBinding vb = getValueBinding("onmouseupeffect");
375
376         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
377     }
378
379     /**
380      * <p>Set the value of the <code>onmouseupeffect</code> property.</p>
381      *
382      * @param onmouseupeffect
383      */

384     public void setOnmouseupeffect(Effect onmouseupeffect) {
385         JavascriptContext
386                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
387         this.onmouseupeffect = onmouseupeffect;
388     }
389
390     /**
391      * <p>Return the value of the <code>onmousemoveeffect</code> property.</p>
392      *
393      * @return Effect
394      */

395     public Effect getOnmousemoveeffect() {
396         if (onmousemoveeffect != null) {
397             return onmousemoveeffect;
398         }
399         ValueBinding vb = getValueBinding("onmousemoveeffect");
400
401         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
402     }
403
404     /**
405      * <p>Set the value of the <code>onmousemoveeffect</code> property.</p>
406      *
407      * @param onmousemoveeffect
408      */

409     public void setOnmousemoveeffect(Effect onmousemoveeffect) {
410         JavascriptContext
411                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
412         this.onmousemoveeffect = onmousemoveeffect;
413     }
414
415     /**
416      * <p>Return the value of the <code>onmouseovereffect</code> property.</p>
417      *
418      * @return Effect
419      */

420     public Effect getOnmouseovereffect() {
421         if (onmouseovereffect != null) {
422             return onmouseovereffect;
423         }
424         ValueBinding vb = getValueBinding("onmouseovereffect");
425
426         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
427     }
428
429     /**
430      * <p>Set the value of the <code>onmouseovereffect</code> property.</p>
431      *
432      * @param onmouseovereffect
433      */

434     public void setOnmouseovereffect(Effect onmouseovereffect) {
435         JavascriptContext
436                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
437         this.onmouseovereffect = onmouseovereffect;
438     }
439
440     /**
441      * <p>Return the value of the <code>onmouseouteffect</code> property.</p>
442      *
443      * @return Effect
444      */

445     public Effect getOnmouseouteffect() {
446         if (onmouseouteffect != null) {
447             return onmouseouteffect;
448         }
449         ValueBinding vb = getValueBinding("onmouseouteffect");
450
451         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
452     }
453
454     /**
455      * <p>Set the value of the <code>onmouseouteffect</code> property.</p>
456      *
457      * @param onmouseouteffect
458      */

459     public void setOnmouseouteffect(Effect onmouseouteffect) {
460         JavascriptContext
461                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
462         this.onmouseouteffect = onmouseouteffect;
463     }
464
465
466     /**
467      * <p>Return the value of the <code>onkeypresseffect</code> property.</p>
468      *
469      * @return Effect
470      */

471     public Effect getOnkeypresseffect() {
472         if (onkeypresseffect != null) {
473             return onkeypresseffect;
474         }
475         ValueBinding vb = getValueBinding("onkeypresseffect");
476
477         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
478     }
479
480     /**
481      * <p>Set the value of the <code>onkeypresseffect</code> property.</p>
482      *
483      * @param onkeypresseffect
484      */

485     public void setOnkeypresseffect(Effect onkeypresseffect) {
486         JavascriptContext
487                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
488         this.onkeypresseffect = onkeypresseffect;
489     }
490
491     /**
492      * <p>Return the value of the <code>onkeydowneffect</code> property.</p>
493      *
494      * @return Effect
495      */

496     public Effect getOnkeydowneffect() {
497         if (onkeydowneffect != null) {
498             return onkeydowneffect;
499         }
500         ValueBinding vb = getValueBinding("onkeydowneffect");
501
502         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
503     }
504
505     /**
506      * <p>Set the value of the <code>onkeydowneffect</code> property.</p>
507      *
508      * @param onkeydowneffect
509      */

510     public void setOnkeydowneffect(Effect onkeydowneffect) {
511         JavascriptContext
512                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
513         this.onkeydowneffect = onkeydowneffect;
514     }
515
516     /**
517      * <p>Return the value of the <code>onkeyupeffect</code> property.</p>
518      *
519      * @return Effect
520      */

521     public Effect getOnkeyupeffect() {
522         if (onkeyupeffect != null) {
523             return onkeyupeffect;
524         }
525         ValueBinding vb = getValueBinding("onkeyupeffect");
526
527         return vb != null ? (Effect) vb.getValue(getFacesContext()) : null;
528     }
529
530     /**
531      * <p>Set the value of the <code>onkeyupeffect</code> property.</p>
532      *
533      * @param onkeyupeffect
534      */

535     public void setOnkeyupeffect(Effect onkeyupeffect) {
536         JavascriptContext
537                 .includeLib(JavascriptContext.ICE_EXTRAS, getFacesContext());
538         this.onkeyupeffect = onkeyupeffect;
539     }
540
541     /**
542      * <p>Return the value of the <code>currentStyle</code> property.</p>
543      *
544      * @return CurrentStyle
545      */

546     public CurrentStyle getCurrentStyle() {
547         return currentStyle;
548     }
549
550     /**
551      * <p>Set the value of the <code>currentStyle</code> property.</p>
552      *
553      * @param currentStyle
554      */

555     public void setCurrentStyle(CurrentStyle currentStyle) {
556         this.currentStyle = currentStyle;
557     }
558
559
560     /**
561      * <p>Gets the state of the instance as a <code>Serializable</code>
562      * Object.</p>
563      *
564      * @param context
565      * @return Object values[]
566      */

567     public Object JavaDoc saveState(FacesContext context) {
568         Object JavaDoc values[] = new Object JavaDoc[21];
569         values[0] = super.saveState(context);
570         values[1] = enabledOnUserRole;
571         values[2] = renderedOnUserRole;
572         values[3] = styleClass;
573         values[4] = effect;
574         values[5] = onclickeffect;
575         values[6] = ondblclickeffect;
576         values[7] = onmousedowneffect;
577         values[8] = onmouseupeffect;
578         values[9] = onmousemoveeffect;
579         values[10] = onmouseovereffect;
580         values[11] = onmouseouteffect;
581
582         values[15] = onkeypresseffect;
583         values[16] = onkeydowneffect;
584         values[17] = onkeyupeffect;
585         values[18] = currentStyle;
586         values[19] = visible;
587         values[20] = partialSubmit;
588         return ((Object JavaDoc) (values));
589     }
590
591     /**
592      * <p>Perform any processing required to restore the state from the entries
593      * in the state Object.</p>
594      *
595      * @param context
596      * @param state
597      */

598     public void restoreState(FacesContext context, Object JavaDoc state) {
599         Object JavaDoc values[] = (Object JavaDoc[]) state;
600         super.restoreState(context, values[0]);
601         enabledOnUserRole = (String JavaDoc) values[1];
602         renderedOnUserRole = (String JavaDoc) values[2];
603         styleClass = (String JavaDoc) values[3];
604         effect = (Effect) values[4];
605
606         onclickeffect = (Effect) values[5];
607         ondblclickeffect = (Effect) values[6];
608         onmousedowneffect = (Effect) values[7];
609         onmouseupeffect = (Effect) values[8];
610         onmousemoveeffect = (Effect) values[9];
611         onmouseovereffect = (Effect) values[10];
612         onmouseouteffect = (Effect) values[11];
613
614         onkeypresseffect = (Effect) values[15];
615         onkeydowneffect = (Effect) values[16];
616         onkeyupeffect = (Effect) values[17];
617         currentStyle = (CurrentStyle) values[18];
618         visible = (Boolean JavaDoc) values[19];
619         partialSubmit = (Boolean JavaDoc) values[20];
620     }
621
622     /**
623      * This method is used to communicate a focus request from the application
624      * to the client browser.
625      */

626     public void requestFocus() {
627         ((BridgeFacesContext) FacesContext.getCurrentInstance())
628                 .setFocusId("null");
629         JavascriptContext.focus(FacesContext.getCurrentInstance(),
630                                 this.getClientId(
631                                         FacesContext.getCurrentInstance()));
632     }
633
634 }
635    
636
637   
Popular Tags