1 16 package org.apache.myfaces.custom.tabbedpane; 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.util.ClassUtils; 27 28 29 51 public class TabChangeListenerTag extends TagSupport 52 { 53 54 private String type = null; 55 56 57 public TabChangeListenerTag() 58 { 59 } 60 61 62 public void setType(String type) 63 { 64 this.type = type; 65 } 66 67 68 public int doStartTag() throws JspException 69 { 70 if (type == null) 71 { 72 throw new JspException ("type attribute not set"); 73 } 74 75 UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext); 77 if (componentTag == null) 78 { 79 throw new JspException ("TabChangeListenerTag has no UIComponentTag ancestor"); 80 } 81 82 if (componentTag.getCreated()) 83 { 84 UIComponent component = componentTag.getComponentInstance(); 86 if (component instanceof HtmlPanelTabbedPane) 87 { 88 String className; 89 if (UIComponentTag.isValueReference(type)) 90 { 91 FacesContext facesContext = FacesContext.getCurrentInstance(); 92 ValueBinding valueBinding = facesContext.getApplication().createValueBinding(type); 93 className = (String ) valueBinding.getValue(facesContext); 94 } else 95 { 96 className = type; 97 } 98 TabChangeListener listener = (TabChangeListener) ClassUtils.newInstance(className); 99 ((HtmlPanelTabbedPane) component).addTabChangeListener(listener); 100 } else 101 { 102 throw new JspException ("Component " + component.getId() + " is no HtmlPanelTabbedPane"); 103 } 104 } 105 106 return Tag.SKIP_BODY; 107 } 108 } 109 | Popular Tags |