1 16 package org.apache.myfaces.wap.base; 17 18 import javax.faces.component.EditableValueHolder; 19 import javax.faces.component.UIComponent; 20 import javax.faces.context.FacesContext; 21 import javax.faces.el.MethodBinding; 22 import javax.faces.el.ValueBinding; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 43 public abstract class EditableValueHolderTagBase extends ValueHolderTagBase { 44 private static Log log = LogFactory.getLog(EditableValueHolderTagBase.class); 45 46 47 private String immediate = null; 48 private String required = null; 49 private String validator = null; 50 private String valueChangeListener = null; 51 52 53 public EditableValueHolderTagBase() { 54 super(); 55 } 56 57 public abstract String getRendererType(); 58 59 public void release() { 60 super.release(); 61 this.immediate = null; 62 this.required = null; 63 this.validator = null; 64 this.valueChangeListener = null; 65 } 66 67 protected void setProperties(UIComponent component) { 68 super.setProperties(component); 69 70 71 Class [] mbParams = {FacesContext.class, UIComponent.class, Object .class}; 72 73 if (immediate != null) { 74 if (component instanceof EditableValueHolder) { 75 if (isValueReference(immediate)) { 76 ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(immediate); 77 component.setValueBinding("immediate", vb); 78 } 79 else { 80 boolean imm = stringToBoolean(immediate); 81 ((EditableValueHolder)component).setImmediate(imm); 82 } 83 84 } 85 else log.error("Component " + component.getClass().getName() + " is no ValueHolder, cannot set 'immediate' attribute."); 86 } 87 88 if (required != null) { 89 if (component instanceof EditableValueHolder) { 90 if (isValueReference(required)) { 91 ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(required); 92 component.setValueBinding("required", vb); 93 } else { 94 boolean req = stringToBoolean(required); 95 ((EditableValueHolder)component).setRequired(req); 96 } 97 } 98 else { 99 log.error("Component " + component.getClass().getName() + " is no EditableValueHolder, cannot set 'required'."); 100 } 101 } 102 103 if (validator != null) { 104 if (component instanceof EditableValueHolder) { 105 if (isValueReference(validator)) { 106 Class [] params = {FacesContext.class, UIComponent.class, Object .class}; 107 108 FacesContext facesContext = FacesContext.getCurrentInstance(); 109 MethodBinding mb = facesContext.getApplication().createMethodBinding(validator, mbParams); 110 ((EditableValueHolder)component).setValidator(mb); 111 } 112 else { 113 log.error("Invalid expression " + validator); 114 } 115 } 116 else { 117 log.error("Component " + component.getClass().getName() + " is no EditableValueHolder, cannot set 'validator'."); 118 } 119 } 120 121 if (valueChangeListener != null) { 122 if (component instanceof EditableValueHolder) { 123 if (isValueReference(valueChangeListener)) { 124 125 FacesContext facesContext = FacesContext.getCurrentInstance(); 126 MethodBinding mb = facesContext.getApplication().createMethodBinding(valueChangeListener, mbParams); 127 ((EditableValueHolder)component).setValueChangeListener(mb); 128 } 129 else { 130 log.error("Invalid expression " + valueChangeListener); 131 } 132 } 133 else { 134 log.error("Component " + component.getClass().getName() + " is no EditableValueHolder, cannot set 'valueChangedListener'."); 135 } 136 } 137 } 138 139 private boolean stringToBoolean(String str){ 140 Boolean bool = Boolean.valueOf(str); 141 return(bool.booleanValue()); 142 } 143 144 149 public String getImmediate() { 150 return immediate; 151 } 152 153 157 public void setImmediate(String immediate) { 158 this.immediate = immediate; 159 } 160 161 public String getRequired() { 162 return required; 163 } 164 165 public void setRequired(String required) { 166 this.required=required; 167 } 168 169 public String getValidator() { 170 return validator; 171 } 172 173 public void setValidator(String validator) { 174 this.validator=validator; 175 } 176 177 public String getValueChangeListener() { 178 return valueChangeListener; 179 } 180 181 public void setValueChangeListener(String valueChangeListener) { 182 this.valueChangeListener=valueChangeListener; 183 } 184 185 186 } 187 | Popular Tags |