1 16 package javax.faces.webapp; 17 18 import javax.faces.component.UIComponent; 19 import javax.faces.context.FacesContext; 20 import javax.faces.el.ValueBinding; 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.tagext.Tag ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 29 public class AttributeTag 30 extends TagSupport 31 { 32 private String _name; 33 private String _value; 34 35 public void setName(String name) 36 { 37 _name = name; 38 } 39 40 public void setValue(String value) 41 { 42 _value = value; 43 } 44 45 public int doStartTag() throws JspException 46 { 47 UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext); 48 if (componentTag == null) 49 { 50 throw new JspException ("no parent UIComponentTag found"); 51 } 52 UIComponent component = componentTag.getComponentInstance(); 53 if (component == null) 54 { 55 throw new JspException ("parent UIComponentTag has no UIComponent"); 56 } 57 String name = getName(); 58 if (component.getAttributes().get(name) == null) 59 { 60 component.getAttributes().put(name, getValue()); 61 } 62 return Tag.SKIP_BODY; 63 } 64 65 public void release() 66 { 67 super.release(); 68 _name = null; 69 _value = null; 70 } 71 72 73 private String getName() 74 { 75 if (UIComponentTag.isValueReference(_name)) 76 { 77 FacesContext facesContext = FacesContext.getCurrentInstance(); 78 ValueBinding vb = facesContext.getApplication().createValueBinding(_name); 79 return (String )vb.getValue(facesContext); 80 } 81 else 82 { 83 return _name; 84 } 85 } 86 87 private String getValue() 88 { 89 if (UIComponentTag.isValueReference(_value)) 90 { 91 FacesContext facesContext = FacesContext.getCurrentInstance(); 92 ValueBinding vb = facesContext.getApplication().createValueBinding(_value); 93 return (String )vb.getValue(facesContext); 94 } 95 else 96 { 97 return _value; 98 } 99 } 100 101 } 102 | Popular Tags |