KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > taglib > html > CommandButtonTag


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.faces.taglib.html;
17
18 import org.apache.cocoon.faces.FacesUtils;
19 import org.apache.cocoon.faces.taglib.UIComponentTag;
20 import org.apache.commons.lang.BooleanUtils;
21
22 import javax.faces.FacesException;
23 import javax.faces.component.UICommand;
24 import javax.faces.component.UIComponent;
25 import javax.faces.el.MethodBinding;
26 import javax.faces.event.ActionEvent;
27
28 /**
29  * @version CVS $Id: CommandButtonTag.java 46253 2004-09-17 14:36:29Z vgritsenko $
30  */

31 public class CommandButtonTag extends UIComponentTag {
32
33     private String JavaDoc action;
34     private String JavaDoc actionListener;
35     private String JavaDoc immediate;
36     private String JavaDoc value;
37     private String JavaDoc accesskey;
38     private String JavaDoc alt;
39     private String JavaDoc dir;
40     private String JavaDoc disabled;
41     private String JavaDoc image;
42     private String JavaDoc lang;
43     private String JavaDoc onblur;
44     private String JavaDoc onchange;
45     private String JavaDoc onclick;
46     private String JavaDoc ondblclick;
47     private String JavaDoc onfocus;
48     private String JavaDoc onkeydown;
49     private String JavaDoc onkeypress;
50     private String JavaDoc onkeyup;
51     private String JavaDoc onmousedown;
52     private String JavaDoc onmousemove;
53     private String JavaDoc onmouseout;
54     private String JavaDoc onmouseover;
55     private String JavaDoc onmouseup;
56     private String JavaDoc onselect;
57     private String JavaDoc readonly;
58     private String JavaDoc style;
59     private String JavaDoc styleClass;
60     private String JavaDoc tabindex;
61     private String JavaDoc title;
62     private String JavaDoc type;
63
64
65     public void setAction(String JavaDoc action) {
66         this.action = action;
67     }
68
69     public void setActionListener(String JavaDoc actionListener) {
70         this.actionListener = actionListener;
71     }
72
73     public void setImmediate(String JavaDoc immediate) {
74         this.immediate = immediate;
75     }
76
77     public void setValue(String JavaDoc value) {
78         this.value = value;
79     }
80
81     public void setAccesskey(String JavaDoc accesskey) {
82         this.accesskey = accesskey;
83     }
84
85     public void setAlt(String JavaDoc alt) {
86         this.alt = alt;
87     }
88
89     public void setDir(String JavaDoc dir) {
90         this.dir = dir;
91     }
92
93     public void setDisabled(String JavaDoc disabled) {
94         this.disabled = disabled;
95     }
96
97     public void setImage(String JavaDoc image) {
98         this.image = image;
99     }
100
101     public void setLang(String JavaDoc lang) {
102         this.lang = lang;
103     }
104
105     public void setOnblur(String JavaDoc onblur) {
106         this.onblur = onblur;
107     }
108
109     public void setOnchange(String JavaDoc onchange) {
110         this.onchange = onchange;
111     }
112
113     public void setOnclick(String JavaDoc onclick) {
114         this.onclick = onclick;
115     }
116
117     public void setOndblclick(String JavaDoc ondblclick) {
118         this.ondblclick = ondblclick;
119     }
120
121     public void setOnfocus(String JavaDoc onfocus) {
122         this.onfocus = onfocus;
123     }
124
125     public void setOnkeydown(String JavaDoc onkeydown) {
126         this.onkeydown = onkeydown;
127     }
128
129     public void setOnkeypress(String JavaDoc onkeypress) {
130         this.onkeypress = onkeypress;
131     }
132
133     public void setOnkeyup(String JavaDoc onkeyup) {
134         this.onkeyup = onkeyup;
135     }
136
137     public void setOnmousedown(String JavaDoc onmousedown) {
138         this.onmousedown = onmousedown;
139     }
140
141     public void setOnmousemove(String JavaDoc onmousemove) {
142         this.onmousemove = onmousemove;
143     }
144
145     public void setOnmouseout(String JavaDoc onmouseout) {
146         this.onmouseout = onmouseout;
147     }
148
149     public void setOnmouseover(String JavaDoc onmouseover) {
150         this.onmouseover = onmouseover;
151     }
152
153     public void setOnmouseup(String JavaDoc onmouseup) {
154         this.onmouseup = onmouseup;
155     }
156
157     public void setOnselect(String JavaDoc onselect) {
158         this.onselect = onselect;
159     }
160
161     public void setReadonly(String JavaDoc readonly) {
162         this.readonly = readonly;
163     }
164
165     public void setStyle(String JavaDoc style) {
166         this.style = style;
167     }
168
169     public void setStyleClass(String JavaDoc styleClass) {
170         this.styleClass = styleClass;
171     }
172
173     public void setTabindex(String JavaDoc tabindex) {
174         this.tabindex = tabindex;
175     }
176
177     public void setTitle(String JavaDoc title) {
178         this.title = title;
179     }
180
181     public void setType(String JavaDoc type) {
182         this.type = type;
183     }
184
185     public String JavaDoc getRendererType() {
186         return "javax.faces.Button";
187     }
188
189     public String JavaDoc getComponentType() {
190         return "javax.faces.HtmlCommandButton";
191     }
192
193
194     protected void setProperties(UIComponent component) {
195         super.setProperties(component);
196
197         UICommand command;
198         try {
199             command = (UICommand) component;
200         } catch (ClassCastException JavaDoc cce) {
201             throw new FacesException("Tag <" + getClass().getName() + "> expected UICommand. " +
202                                      "Got <" + component.getClass().getName() + ">");
203         }
204
205         if (action != null) {
206             MethodBinding vb;
207             if (FacesUtils.isExpression(action)) {
208                 vb = getApplication().createMethodBinding(action, null);
209             } else {
210                 vb = new ConstantMethodBinding(action);
211             }
212             command.setAction(vb);
213         }
214
215         if (actionListener != null) {
216             if (FacesUtils.isExpression(actionListener)) {
217                 MethodBinding vb = getApplication().createMethodBinding(actionListener,
218                                                                         new Class JavaDoc[]{ ActionEvent.class });
219                 command.setActionListener(vb);
220             } else {
221                 throw new FacesException("Tag <" + getClass().getName() + "> actionListener must be an expression. " +
222                                          "Got <" + actionListener + ">");
223             }
224         }
225
226         if (immediate != null) {
227             if (FacesUtils.isExpression(immediate)) {
228                 command.setValueBinding("immediate", createValueBinding(immediate));
229             } else {
230                 command.setImmediate(BooleanUtils.toBoolean(immediate));
231             }
232         }
233
234         if (value != null) {
235             if (FacesUtils.isExpression(value)) {
236                 command.setValueBinding("value", createValueBinding(value));
237             } else {
238                 command.setValue(value);
239             }
240         }
241
242         setProperty(component, "accesskey", accesskey);
243         setProperty(component, "alt", alt);
244         setProperty(component, "dir", dir);
245
246         setBooleanProperty(component, "disabled", disabled);
247
248         setProperty(component, "image", image);
249         setProperty(component, "lang", lang);
250         setProperty(component, "onblur", onblur);
251         setProperty(component, "onchange", onchange);
252         setProperty(component, "onclick", onclick);
253         setProperty(component, "ondblclick", ondblclick);
254         setProperty(component, "onfocus", onfocus);
255         setProperty(component, "onkeydown", onkeydown);
256         setProperty(component, "onkeypress", onkeypress);
257         setProperty(component, "onkeyup", onkeyup);
258         setProperty(component, "onmousedown", onmousedown);
259         setProperty(component, "onmousemove", onmousemove);
260         setProperty(component, "onmouseout", onmouseout);
261         setProperty(component, "onmouseover", onmouseover);
262         setProperty(component, "onmouseup", onmouseup);
263         setProperty(component, "onselect", onselect);
264
265         setBooleanProperty(component, "readonly", readonly);
266
267         setProperty(component, "style", style);
268         setProperty(component, "styleClass", styleClass);
269         setProperty(component, "tabindex", tabindex);
270         setProperty(component, "title", title);
271         setProperty(component, "type", type);
272     }
273
274     public void recycle() {
275         super.recycle();
276         action = null;
277         actionListener = null;
278         immediate = null;
279         value = null;
280         accesskey = null;
281         alt = null;
282         dir = null;
283         disabled = null;
284         image = null;
285         lang = null;
286         onblur = null;
287         onchange = null;
288         onclick = null;
289         ondblclick = null;
290         onfocus = null;
291         onkeydown = null;
292         onkeypress = null;
293         onkeyup = null;
294         onmousedown = null;
295         onmousemove = null;
296         onmouseout = null;
297         onmouseover = null;
298         onmouseup = null;
299         onselect = null;
300         readonly = null;
301         style = null;
302         styleClass = null;
303         tabindex = null;
304         title = null;
305         type = null;
306     }
307 }
308
Popular Tags