1 16 package org.apache.myfaces.wap.base; 17 18 import javax.faces.component.UIComponent; 19 import javax.faces.component.ValueHolder; 20 import javax.faces.context.FacesContext; 21 import javax.faces.convert.Converter; 22 import javax.faces.el.ValueBinding; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 41 public abstract class ValueHolderTagBase extends ComponentTagBase { 42 private static Log log = LogFactory.getLog(ValueHolderTagBase.class); 43 44 45 private String converter = null; 46 private String value = null; 47 48 49 public ValueHolderTagBase() { 50 super(); 51 } 52 53 public abstract String getRendererType(); 54 55 public void release() { 56 super.release(); 57 this.converter = null; 58 this.value = null; 59 } 60 61 protected void setProperties(UIComponent component) { 62 super.setProperties(component); 63 64 if (converter != null) { 65 if (component instanceof ValueHolder) { 66 if (isValueReference(converter)) { 67 ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(converter); 68 component.setValueBinding("converter", vb); 69 } 70 else { 71 FacesContext facesContext = FacesContext.getCurrentInstance(); 72 Converter conv = facesContext.getApplication().createConverter(converter); 73 ((ValueHolder)component).setConverter(conv); 74 } 75 } 76 else { 77 log.error("Component " + component.getClass().getName() + " is no ValueHolder, cannot set 'converter' attribute."); 78 } 79 } 80 81 82 if (value != null) { 83 if (component instanceof ValueHolder) { 84 if (isValueReference(value)) { 85 ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(value); 86 component.setValueBinding("value", vb); 87 } else 88 ((ValueHolder)component).setValue(value); 89 90 } 91 else log.error("Component " + component.getClass().getName() + " is no ValueHolder, cannot set 'value' attribute."); 92 } 93 94 } 95 97 101 public String getConverter() { 102 return converter; 103 } 104 105 109 public void setConverter(String converter) { 110 this.converter = converter; 111 } 112 113 117 public String getValue() { 118 return value; 119 } 120 121 125 public void setValue(String value) { 126 this.value = value; 127 } 128 } 129 | Popular Tags |