1 17 package org.alfresco.web.ui.common.tag; 18 19 import javax.faces.FacesException; 20 import javax.faces.component.UICommand; 21 import javax.faces.component.UIComponent; 22 import javax.faces.el.MethodBinding; 23 import javax.faces.el.ValueBinding; 24 import javax.faces.webapp.UIComponentTag; 25 26 import org.alfresco.web.ui.common.ConstantMethodBinding; 27 28 31 public abstract class BaseComponentTag extends UIComponentTag 32 { 33 39 protected void setActionProperty(UICommand command, String action) 40 { 41 if (action != null) 42 { 43 if (isValueReference(action)) 44 { 45 MethodBinding vb = getFacesContext().getApplication().createMethodBinding(action, null); 46 command.setAction(vb); 47 } 48 else 49 { 50 MethodBinding vb = new ConstantMethodBinding(action); 51 command.setAction(vb); 52 } 53 } 54 } 55 56 62 protected void setActionListenerProperty(UICommand command, String actionListener) 63 { 64 if (actionListener != null) 65 { 66 if (isValueReference(actionListener)) 67 { 68 MethodBinding vb = getFacesContext().getApplication().createMethodBinding(actionListener, ACTION_CLASS_ARGS); 69 command.setActionListener(vb); 70 } 71 else 72 { 73 throw new FacesException("Action listener method binding incorrectly specified: " + actionListener); 74 } 75 } 76 } 77 78 86 protected void setStringProperty(UIComponent component, String name, String value) 87 { 88 if (value != null) 89 { 90 if (isValueReference(value)) 91 { 92 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value); 93 component.setValueBinding(name, vb); 94 } 95 else 96 { 97 component.getAttributes().put(name, value); 98 } 99 } 100 } 101 102 110 protected void setStringBindingProperty(UIComponent component, String name, String value) 111 { 112 if (value != null) 113 { 114 if (isValueReference(value)) 115 { 116 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value); 117 component.setValueBinding(name, vb); 118 } 119 else 120 { 121 throw new IllegalArgumentException ("Property: '" + name + "' must be a value binding expression."); 122 } 123 } 124 } 125 126 134 protected void setStringStaticProperty(UIComponent component, String name, String value) 135 { 136 if (value != null) 137 { 138 component.getAttributes().put(name, value); 139 } 140 } 141 142 150 protected void setIntProperty(UIComponent component, String name, String value) 151 { 152 if (value != null) 153 { 154 if (isValueReference(value)) 155 { 156 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value); 157 component.setValueBinding(name, vb); 158 } 159 else 160 { 161 try 162 { 163 component.getAttributes().put(name, Integer.valueOf(value)); 164 } 165 catch (NumberFormatException ne) 166 { 167 throw new RuntimeException ("Was expecting Int value for property '" + name + "' but passed value: " + value); 168 } 169 } 170 } 171 } 172 173 protected void setIntStaticProperty(UIComponent component, String name, String value) 174 { 175 if (value != null) 176 { 177 try 178 { 179 component.getAttributes().put(name, Integer.valueOf(value)); 180 } 181 catch (NumberFormatException ne) 182 { 183 throw new RuntimeException ("Was expecting Int value for property '" + name + "' but passed value: " + value); 184 } 185 } 186 } 187 188 196 protected void setBooleanProperty(UIComponent component, String name, String value) 197 { 198 if (value != null) 199 { 200 if (isValueReference(value)) 201 { 202 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value); 203 component.setValueBinding(name, vb); 204 } 205 else 206 { 207 component.getAttributes().put(name, Boolean.valueOf(value)); 208 } 209 } 210 } 211 212 protected void setBooleanStaticProperty(UIComponent component, String name, String value) 213 { 214 if (value != null) 215 { 216 component.getAttributes().put(name, Boolean.valueOf(value)); 217 } 218 } 219 220 protected final static Class ACTION_CLASS_ARGS[] = {javax.faces.event.ActionEvent.class}; 221 } 222 | Popular Tags |