KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > taglib > CommandLinkTag


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.taglib;
18
19
20 import javax.faces.component.ActionSource;
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import javax.faces.el.MethodBinding;
24
25
26 /**
27  * <p>Render a <code>CommandLinkComponent</code> inside a
28  * Struts-Faces <code>FormComponent</code>.</p>
29  *
30  * @version $Rev: 54934 $ $Date: 2004-10-16 18:07:50 +0100 (Sat, 16 Oct 2004) $
31  */

32
33 public class CommandLinkTag extends AbstractFacesTag {
34
35
36     // ------------------------------------------------------ Instance Variables
37

38
39     private String JavaDoc accesskey = null;
40     private String JavaDoc action = null;
41     private String JavaDoc charset = null;
42     private String JavaDoc dir = null;
43     private String JavaDoc hreflang = null;
44     private String JavaDoc immediate = null;
45     private String JavaDoc lang = null;
46     private String JavaDoc onblur = null;
47     private String JavaDoc onclick = null;
48     private String JavaDoc ondblclick = null;
49     private String JavaDoc onfocus = null;
50     private String JavaDoc onkeydown = null;
51     private String JavaDoc onkeypress = null;
52     private String JavaDoc onkeyup = null;
53     private String JavaDoc onmousedown = null;
54     private String JavaDoc onmousemove = null;
55     private String JavaDoc onmouseout = null;
56     private String JavaDoc onmouseover = null;
57     private String JavaDoc onmouseup = null;
58     private String JavaDoc rel = null;
59     private String JavaDoc rev = null;
60     private String JavaDoc style = null;
61     private String JavaDoc styleClass = null;
62     private String JavaDoc tabindex = null;
63     private String JavaDoc target = null;
64     private String JavaDoc title = null;
65     private String JavaDoc type = null;
66
67
68     // ---------------------------------------------------------- Tag Attributes
69

70
71     public void setAccesskey(String JavaDoc accesskey) {
72         this.accesskey = accesskey;
73     }
74
75
76     public void setAction(String JavaDoc action) {
77         this.action = action;
78     }
79
80
81     public void setCharset(String JavaDoc charset) {
82         this.charset = charset;
83     }
84
85
86     public void setDir(String JavaDoc dir) {
87         this.dir = dir;
88     }
89
90
91     public void setHreflang(String JavaDoc hreflang) {
92         this.hreflang = hreflang;
93     }
94
95
96     public void setImmediate(String JavaDoc immediate) {
97         this.immediate = immediate;
98     }
99
100
101     public void setLang(String JavaDoc lang) {
102         this.lang = lang;
103     }
104
105
106     public void setOnblur(String JavaDoc onblur) {
107         this.onblur = onblur;
108     }
109
110
111     public void setOnclick(String JavaDoc onclick) {
112         this.onclick = onclick;
113     }
114
115
116     public void setOndblclick(String JavaDoc ondblclick) {
117         this.ondblclick = ondblclick;
118     }
119
120
121     public void setOnfocus(String JavaDoc onfocus) {
122         this.onfocus = onfocus;
123     }
124
125
126     public void setOnkeydown(String JavaDoc onkeydown) {
127         this.onkeydown = onkeydown;
128     }
129
130
131     public void setOnkeypress(String JavaDoc onkeypress) {
132         this.onkeypress = onkeypress;
133     }
134
135
136     public void setOnkeyup(String JavaDoc onkeyup) {
137         this.onkeyup = onkeyup;
138     }
139
140
141     public void setOnmousedown(String JavaDoc onmousedown) {
142         this.onmousedown = onmousedown;
143     }
144
145
146     public void setOnmousemove(String JavaDoc onmousemove) {
147         this.onmousemove = onmousemove;
148     }
149
150
151     public void setOnmouseout(String JavaDoc onmouseout) {
152         this.onmouseout = onmouseout;
153     }
154
155
156     public void setOnmouseover(String JavaDoc onmouseover) {
157         this.onmouseover = onmouseover;
158     }
159
160
161     public void setOnmouseup(String JavaDoc onmouseup) {
162         this.onmouseup = onmouseup;
163     }
164
165
166     public void setRel(String JavaDoc rel) {
167         this.rel = rel;
168     }
169
170
171     public void setRev(String JavaDoc rev) {
172         this.rev = rev;
173     }
174
175
176     public void setStyle(String JavaDoc style) {
177         this.style = style;
178     }
179
180
181     public void setStyleClass(String JavaDoc styleClass) {
182         this.styleClass = styleClass;
183     }
184
185
186     public void setTabindex(String JavaDoc tabindex) {
187         this.tabindex = tabindex;
188     }
189
190
191     public void setTarget(String JavaDoc target) {
192         this.target = target;
193     }
194
195
196     public void setTitle(String JavaDoc title) {
197         this.title = title;
198     }
199
200
201     public void setType(String JavaDoc type) {
202         this.type = type;
203     }
204
205
206     // ------------------------------------------------------------- Tag Methods
207

208
209     /**
210      * <p>Release any allocated resources.</p>
211      */

212     public void release() {
213
214         super.release();
215         accesskey = null;
216         action = null;
217         charset = null;
218         dir = null;
219         hreflang = null;
220         immediate = null;
221         lang = null;
222         onblur = null;
223         onclick = null;
224         ondblclick = null;
225         onfocus = null;
226         onkeydown = null;
227         onkeypress = null;
228         onkeyup = null;
229         onmousedown = null;
230         onmousemove = null;
231         onmouseout = null;
232         onmouseover = null;
233         onmouseup = null;
234         rel = null;
235         rev = null;
236         style = null;
237         styleClass = null;
238         tabindex = null;
239         target = null;
240         title = null;
241         type = null;
242
243     }
244
245
246     // ---------------------------------------------------------- Public Methods
247

248
249     /**
250      * <p>Return the type of component to be created for this tag.</p>
251      */

252     public String JavaDoc getComponentType() {
253
254         return ("org.apache.struts.faces.CommandLink");
255
256     }
257
258
259     /**
260      * <p>Return the <code>rendererType</code> to be used for rendering
261      * our component.</p>
262      */

263     public String JavaDoc getRendererType() {
264
265         return ("org.apache.struts.faces.CommandLink");
266
267     }
268
269
270     // ------------------------------------------------------- Protected Methods
271

272
273     /**
274      * <p>Override attributes set on this tag instance.</p>
275      *
276      * @param component Component whose attributes should be overridden
277      */

278     protected void setProperties(UIComponent component) {
279
280         super.setProperties(component);
281         if (action != null) {
282             if (isValueReference(action)) {
283                 MethodBinding mb = FacesContext.getCurrentInstance().
284                     getApplication().createMethodBinding(action, null);
285                 ((ActionSource) component).setAction(mb);
286             } else {
287                 final String JavaDoc outcome = action;
288                 MethodBinding mb = new ConstantMethodBinding(outcome);
289                 ((ActionSource) component).setAction(mb);
290             }
291         }
292         setStringAttribute(component, "accesskey", accesskey);
293         setStringAttribute(component, "charset", charset);
294         setStringAttribute(component, "dir", dir);
295         setStringAttribute(component, "hreflang", hreflang);
296         setBooleanAttribute(component, "immediate", immediate);
297         setStringAttribute(component, "lang", lang);
298         setStringAttribute(component, "onblur", onblur);
299         setStringAttribute(component, "onclick", onclick);
300         setStringAttribute(component, "ondblclick", ondblclick);
301         setStringAttribute(component, "onfocus", onfocus);
302         setStringAttribute(component, "onkeydown", onkeydown);
303         setStringAttribute(component, "onkeypress", onkeypress);
304         setStringAttribute(component, "onkeyup", onkeyup);
305         setStringAttribute(component, "onmousedown", onmousedown);
306         setStringAttribute(component, "onmousemove", onmousemove);
307         setStringAttribute(component, "onmouseout", onmouseout);
308         setStringAttribute(component, "onmouseover", onmouseover);
309         setStringAttribute(component, "onmouseup", onmouseup);
310         setStringAttribute(component, "rel", rel);
311         setStringAttribute(component, "rev", rev);
312         setStringAttribute(component, "style", style);
313         setStringAttribute(component, "styleClass", styleClass);
314         setStringAttribute(component, "tabindex", tabindex);
315         setStringAttribute(component, "target", target);
316         setStringAttribute(component, "title", title);
317         setStringAttribute(component, "type", type);
318
319     }
320
321
322 }
323
324
325 // Private MethodBinding Implementation To Return A Constant Value
326

327 class ConstantMethodBinding extends MethodBinding {
328
329     public ConstantMethodBinding(String JavaDoc outcome) {
330         this.outcome = outcome;
331     }
332
333     private String JavaDoc outcome = null;
334
335     public Object JavaDoc invoke(FacesContext context, Object JavaDoc params[]) {
336         return (this.outcome);
337     }
338
339     public Class JavaDoc getType(FacesContext context) {
340         return (String JavaDoc.class);
341     }
342
343
344 }
345
Popular Tags