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