View Javadoc

1   /*
2    * Copyright 2002-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.struts.faces.component;
18  
19  
20  import javax.faces.component.UICommand;
21  import javax.faces.context.FacesContext;
22  import javax.faces.el.ValueBinding;
23  
24  
25  /***
26   * <p>Custom component that emulates the JSF standard component class
27   * <code>javax.faces.component.html.HtmlCommandLink</code> (and its
28   * corresponding renderer) but is not tied to a particular implementation of
29   * renderer for <code>javax.faces.component.UIForm</code>.</p>
30   */
31  
32  public class CommandLinkComponent extends UICommand {
33  
34  
35      // ------------------------------------------------------------ Constructors
36  
37  
38      /***
39       * <p>Create a new {@link CommandLinkComponent} with default properties.</p>
40       */
41      public CommandLinkComponent() {
42  
43          super();
44          setRendererType("org.apache.struts.faces.CommandLink");
45  
46      }
47  
48  
49      // ------------------------------------------------------ Instance Variables
50  
51  
52      private String accesskey = null;
53      private String charset = null;
54      private String dir = null;
55      private String hreflang = null;
56      private String lang = null;
57      private String onblur = null;
58      private String onclick = null;
59      private String ondblclick = null;
60      private String onfocus = null;
61      private String onkeydown = null;
62      private String onkeypress = null;
63      private String onkeyup = null;
64      private String onmousedown = null;
65      private String onmousemove = null;
66      private String onmouseout = null;
67      private String onmouseover = null;
68      private String onmouseup = null;
69      private String rel = null;
70      private String rev = null;
71      private String style = null;
72      private String styleClass = null;
73      private String tabindex = null;
74      private String target = null;
75      private String title = null;
76      private String type = null;
77  
78  
79  
80      // ---------------------------------------------------- Component Properties
81  
82  
83      public String getAccesskey() {
84          ValueBinding vb = getValueBinding("accesskey");
85          if (vb != null) {
86              return (String) vb.getValue(getFacesContext());
87          } else {
88              return accesskey;
89          }
90      }
91  
92      public void setAccesskey(String accesskey) {
93          this.accesskey = accesskey;
94      }
95  
96  
97      public String getCharset() {
98          ValueBinding vb = getValueBinding("charset");
99          if (vb != null) {
100             return (String) vb.getValue(getFacesContext());
101         } else {
102             return charset;
103         }
104     }
105 
106     public void setCharset(String charset) {
107         this.charset = charset;
108     }
109 
110 
111     public String getDir() {
112         ValueBinding vb = getValueBinding("dir");
113         if (vb != null) {
114             return (String) vb.getValue(getFacesContext());
115         } else {
116             return dir;
117         }
118     }
119 
120     public void setDir(String dir) {
121         this.dir = dir;
122     }
123 
124 
125     /***
126      * <p>Return the component family to which this component belongs.</p>
127      */
128     public String getFamily() {
129 
130         return "org.apache.struts.faces.CommandLink";
131 
132     }
133 
134 
135     public String getHreflang() {
136         ValueBinding vb = getValueBinding("hreflang");
137         if (vb != null) {
138             return (String) vb.getValue(getFacesContext());
139         } else {
140             return hreflang;
141         }
142     }
143 
144     public void setHreflang(String hreflang) {
145         this.hreflang = hreflang;
146     }
147 
148 
149     public String getLang() {
150         ValueBinding vb = getValueBinding("lang");
151         if (vb != null) {
152             return (String) vb.getValue(getFacesContext());
153         } else {
154             return lang;
155         }
156     }
157 
158     public void setLang(String lang) {
159         this.lang = lang;
160     }
161 
162 
163     public String getOnblur() {
164         ValueBinding vb = getValueBinding("onblur");
165         if (vb != null) {
166             return (String) vb.getValue(getFacesContext());
167         } else {
168             return onblur;
169         }
170     }
171 
172     public void setOnblur(String onblur) {
173         this.onblur = onblur;
174     }
175 
176 
177     public String getOnclick() {
178         ValueBinding vb = getValueBinding("onclick");
179         if (vb != null) {
180             return (String) vb.getValue(getFacesContext());
181         } else {
182             return onclick;
183         }
184     }
185 
186     public void setOnclick(String onclick) {
187         this.onclick = onclick;
188     }
189 
190 
191     public String getOndblclick() {
192         ValueBinding vb = getValueBinding("ondblclick");
193         if (vb != null) {
194             return (String) vb.getValue(getFacesContext());
195         } else {
196             return ondblclick;
197         }
198     }
199 
200     public void setOndblclick(String ondblclick) {
201         this.ondblclick = ondblclick;
202     }
203 
204 
205     public String getOnfocus() {
206         ValueBinding vb = getValueBinding("onfocus");
207         if (vb != null) {
208             return (String) vb.getValue(getFacesContext());
209         } else {
210             return onfocus;
211         }
212     }
213 
214     public void setOnfocus(String onfocus) {
215         this.onfocus = onfocus;
216     }
217 
218 
219     public String getOnkeydown() {
220         ValueBinding vb = getValueBinding("onkeydown");
221         if (vb != null) {
222             return (String) vb.getValue(getFacesContext());
223         } else {
224             return onkeydown;
225         }
226     }
227 
228     public void setOnkeydown(String onkeydown) {
229         this.onkeydown = onkeydown;
230     }
231 
232 
233     public String getOnkeypress() {
234         ValueBinding vb = getValueBinding("onkeypress");
235         if (vb != null) {
236             return (String) vb.getValue(getFacesContext());
237         } else {
238             return onkeypress;
239         }
240     }
241 
242     public void setOnkeypress(String onkeypress) {
243         this.onkeypress = onkeypress;
244     }
245 
246 
247     public String getOnkeyup() {
248         ValueBinding vb = getValueBinding("onkeyup");
249         if (vb != null) {
250             return (String) vb.getValue(getFacesContext());
251         } else {
252             return onkeyup;
253         }
254     }
255 
256     public void setOnkeyup(String onkeyup) {
257         this.onkeyup = onkeyup;
258     }
259 
260 
261     public String getOnmousedown() {
262         ValueBinding vb = getValueBinding("onmousedown");
263         if (vb != null) {
264             return (String) vb.getValue(getFacesContext());
265         } else {
266             return onmousedown;
267         }
268     }
269 
270     public void setOnmousedown(String onmousedown) {
271         this.onmousedown = onmousedown;
272     }
273 
274 
275     public String getOnmousemove() {
276         ValueBinding vb = getValueBinding("onmousemove");
277         if (vb != null) {
278             return (String) vb.getValue(getFacesContext());
279         } else {
280             return onmousemove;
281         }
282     }
283 
284     public void setOnmousemove(String onmousemove) {
285         this.onmousemove = onmousemove;
286     }
287 
288 
289     public String getOnmouseout() {
290         ValueBinding vb = getValueBinding("onmouseout");
291         if (vb != null) {
292             return (String) vb.getValue(getFacesContext());
293         } else {
294             return onmouseout;
295         }
296     }
297 
298     public void setOnmouseout(String onmouseout) {
299         this.onmouseout = onmouseout;
300     }
301 
302 
303     public String getOnmouseover() {
304         ValueBinding vb = getValueBinding("onmouseover");
305         if (vb != null) {
306             return (String) vb.getValue(getFacesContext());
307         } else {
308             return onmouseover;
309         }
310     }
311 
312     public void setOnmouseover(String onmouseover) {
313         this.onmouseover = onmouseover;
314     }
315 
316 
317     public String getOnmouseup() {
318         ValueBinding vb = getValueBinding("onmouseup");
319         if (vb != null) {
320             return (String) vb.getValue(getFacesContext());
321         } else {
322             return onmouseup;
323         }
324     }
325 
326     public void setOnmouseup(String onmouseup) {
327         this.onmouseup = onmouseup;
328     }
329 
330 
331     public String getRel() {
332         ValueBinding vb = getValueBinding("rel");
333         if (vb != null) {
334             return (String) vb.getValue(getFacesContext());
335         } else {
336             return rel;
337         }
338     }
339 
340     public void setRel(String rel) {
341         this.rel = rel;
342     }
343 
344 
345     public String getRev() {
346         ValueBinding vb = getValueBinding("rev");
347         if (vb != null) {
348             return (String) vb.getValue(getFacesContext());
349         } else {
350             return rev;
351         }
352     }
353 
354     public void setRev(String rev) {
355         this.rev = rev;
356     }
357 
358 
359     public String getStyle() {
360         ValueBinding vb = getValueBinding("style");
361         if (vb != null) {
362             return (String) vb.getValue(getFacesContext());
363         } else {
364             return style;
365         }
366     }
367 
368     public void setStyle(String style) {
369         this.style = style;
370     }
371 
372 
373     public String getStyleClass() {
374         ValueBinding vb = getValueBinding("styleClass");
375         if (vb != null) {
376             return (String) vb.getValue(getFacesContext());
377         } else {
378             return styleClass;
379         }
380     }
381 
382     public void setStyleClass(String styleClass) {
383         this.styleClass = styleClass;
384     }
385 
386 
387     public String getTabindex() {
388         ValueBinding vb = getValueBinding("tabindex");
389         if (vb != null) {
390             return (String) vb.getValue(getFacesContext());
391         } else {
392             return tabindex;
393         }
394     }
395 
396     public void setTabindex(String tabindex) {
397         this.tabindex = tabindex;
398     }
399 
400 
401     public String getTarget() {
402         ValueBinding vb = getValueBinding("target");
403         if (vb != null) {
404             return (String) vb.getValue(getFacesContext());
405         } else {
406             return target;
407         }
408     }
409 
410     public void setTarget(String target) {
411         this.target = target;
412     }
413 
414 
415     public String getTitle() {
416         ValueBinding vb = getValueBinding("title");
417         if (vb != null) {
418             return (String) vb.getValue(getFacesContext());
419         } else {
420             return title;
421         }
422     }
423 
424     public void setTitle(String title) {
425         this.title = title;
426     }
427 
428 
429     public String getType() {
430         ValueBinding vb = getValueBinding("type");
431         if (vb != null) {
432             return (String) vb.getValue(getFacesContext());
433         } else {
434             return type;
435         }
436     }
437 
438     public void setType(String type) {
439         this.type = type;
440     }
441 
442 
443     // ---------------------------------------------------- StateManager Methods
444 
445 
446     /***
447      * <p>Restore the state of this component.</p>
448      *
449      * @param context <code>FacesContext</code> for the current request
450      * @param state State object from which to restore our state
451      */
452     public void restoreState(FacesContext context, Object state) {
453 
454         Object values[] = (Object[]) state;
455         super.restoreState(context, values[0]);
456         accesskey = (String) values[1];
457         charset = (String) values[2];
458         dir = (String) values[3];
459         hreflang = (String) values[4];
460         lang = (String) values[5];
461         onblur = (String) values[6];
462         onclick = (String) values[7];
463         ondblclick = (String) values[8];
464         onfocus = (String) values[9];
465         onkeydown = (String) values[10];
466         onkeypress = (String) values[11];
467         onkeyup = (String) values[12];
468         onmousedown = (String) values[13];
469         onmousemove = (String) values[14];
470         onmouseout = (String) values[15];
471         onmouseover = (String) values[16];
472         onmouseup = (String) values[17];
473         rel = (String) values[18];
474         rev = (String) values[19];
475         style = (String) values[20];
476         styleClass = (String) values[21];
477         tabindex = (String) values[22];
478         target = (String) values[23];
479         title = (String) values[24];
480         type = (String) values[25];
481 
482     }
483 
484 
485     /***
486      * <p>Save the state of this component.</p>
487      *
488      * @param context <code>FacesContext</code> for the current request
489      */
490     public Object saveState(FacesContext context) {
491 
492         Object values[] = new Object[26];
493         values[0] = super.saveState(context);
494         values[1] = accesskey;
495         values[2] = charset;
496         values[3] = dir;
497         values[4] = hreflang;
498         values[5] = lang;
499         values[6] = onblur;
500         values[7] = onclick;
501         values[8] = ondblclick;
502         values[9] = onfocus;
503         values[10] = onkeydown;
504         values[11] = onkeypress;
505         values[12] = onkeyup;
506         values[13] = onmousedown;
507         values[14] = onmousemove;
508         values[15] = onmouseout;
509         values[16] = onmouseover;
510         values[17] = onmouseup;
511         values[18] = rel;
512         values[19] = rev;
513         values[20] = style;
514         values[21] = styleClass;
515         values[22] = tabindex;
516         values[23] = target;
517         values[24] = title;
518         values[25] = type;
519         return values;
520 
521     }
522 
523 
524 }