1 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 31 public class CommandButtonTag extends UIComponentTag { 32 33 private String action; 34 private String actionListener; 35 private String immediate; 36 private String value; 37 private String accesskey; 38 private String alt; 39 private String dir; 40 private String disabled; 41 private String image; 42 private String lang; 43 private String onblur; 44 private String onchange; 45 private String onclick; 46 private String ondblclick; 47 private String onfocus; 48 private String onkeydown; 49 private String onkeypress; 50 private String onkeyup; 51 private String onmousedown; 52 private String onmousemove; 53 private String onmouseout; 54 private String onmouseover; 55 private String onmouseup; 56 private String onselect; 57 private String readonly; 58 private String style; 59 private String styleClass; 60 private String tabindex; 61 private String title; 62 private String type; 63 64 65 public void setAction(String action) { 66 this.action = action; 67 } 68 69 public void setActionListener(String actionListener) { 70 this.actionListener = actionListener; 71 } 72 73 public void setImmediate(String immediate) { 74 this.immediate = immediate; 75 } 76 77 public void setValue(String value) { 78 this.value = value; 79 } 80 81 public void setAccesskey(String accesskey) { 82 this.accesskey = accesskey; 83 } 84 85 public void setAlt(String alt) { 86 this.alt = alt; 87 } 88 89 public void setDir(String dir) { 90 this.dir = dir; 91 } 92 93 public void setDisabled(String disabled) { 94 this.disabled = disabled; 95 } 96 97 public void setImage(String image) { 98 this.image = image; 99 } 100 101 public void setLang(String lang) { 102 this.lang = lang; 103 } 104 105 public void setOnblur(String onblur) { 106 this.onblur = onblur; 107 } 108 109 public void setOnchange(String onchange) { 110 this.onchange = onchange; 111 } 112 113 public void setOnclick(String onclick) { 114 this.onclick = onclick; 115 } 116 117 public void setOndblclick(String ondblclick) { 118 this.ondblclick = ondblclick; 119 } 120 121 public void setOnfocus(String onfocus) { 122 this.onfocus = onfocus; 123 } 124 125 public void setOnkeydown(String onkeydown) { 126 this.onkeydown = onkeydown; 127 } 128 129 public void setOnkeypress(String onkeypress) { 130 this.onkeypress = onkeypress; 131 } 132 133 public void setOnkeyup(String onkeyup) { 134 this.onkeyup = onkeyup; 135 } 136 137 public void setOnmousedown(String onmousedown) { 138 this.onmousedown = onmousedown; 139 } 140 141 public void setOnmousemove(String onmousemove) { 142 this.onmousemove = onmousemove; 143 } 144 145 public void setOnmouseout(String onmouseout) { 146 this.onmouseout = onmouseout; 147 } 148 149 public void setOnmouseover(String onmouseover) { 150 this.onmouseover = onmouseover; 151 } 152 153 public void setOnmouseup(String onmouseup) { 154 this.onmouseup = onmouseup; 155 } 156 157 public void setOnselect(String onselect) { 158 this.onselect = onselect; 159 } 160 161 public void setReadonly(String readonly) { 162 this.readonly = readonly; 163 } 164 165 public void setStyle(String style) { 166 this.style = style; 167 } 168 169 public void setStyleClass(String styleClass) { 170 this.styleClass = styleClass; 171 } 172 173 public void setTabindex(String tabindex) { 174 this.tabindex = tabindex; 175 } 176 177 public void setTitle(String title) { 178 this.title = title; 179 } 180 181 public void setType(String type) { 182 this.type = type; 183 } 184 185 public String getRendererType() { 186 return "javax.faces.Button"; 187 } 188 189 public String 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 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 []{ 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 |