1 16 package org.apache.myfaces.custom.tree.taglib; 17 18 import org.apache.myfaces.util.ClassUtils; 19 import org.apache.myfaces.custom.tree.HtmlTree; 20 import org.apache.myfaces.custom.tree.IconProvider; 21 22 import javax.faces.component.UIComponent; 23 import javax.faces.context.FacesContext; 24 import javax.faces.el.ValueBinding; 25 import javax.faces.webapp.UIComponentTag; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.Tag ; 28 import javax.servlet.jsp.tagext.TagSupport ; 29 30 31 45 public class IconProviderTag 46 extends TagSupport 47 { 48 49 private String type = null; 50 51 52 public IconProviderTag() 53 { 54 } 55 56 57 public void setType(String type) 58 { 59 this.type = type; 60 } 61 62 63 public int doStartTag() throws JspException 64 { 65 if (type == null) 66 { 67 throw new JspException ("type attribute not set"); 68 } 69 70 UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext); 72 if (componentTag == null) 73 { 74 throw new JspException ("IconProviderTag has no UIComponentTag ancestor"); 75 } 76 77 UIComponent component = componentTag.getComponentInstance(); 78 if (component instanceof HtmlTree) 79 { 80 String className; 81 if (UIComponentTag.isValueReference(type)) 82 { 83 FacesContext facesContext = FacesContext.getCurrentInstance(); 84 ValueBinding vb = facesContext.getApplication().createValueBinding(type); 85 className = (String ) vb.getValue(facesContext); 86 } else 87 { 88 className = type; 89 } 90 IconProvider provider = (IconProvider) ClassUtils.newInstance(className); 91 ((HtmlTree) component).setIconProvider(provider); 92 } else 93 { 94 throw new JspException ("Component " + component.getId() + " is no HtmlTree"); 95 } 96 97 return Tag.SKIP_BODY; 98 } 99 } 100 | Popular Tags |