1 16 17 package com.icesoft.faces.component.paneltabset; 18 19 import com.icesoft.faces.component.util.CustomComponentUtils; 20 21 import javax.faces.component.UIComponent; 22 import javax.faces.context.FacesContext; 23 import javax.faces.el.ValueBinding; 24 import javax.faces.webapp.UIComponentTag; 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.tagext.Tag ; 27 import javax.servlet.jsp.tagext.TagSupport ; 28 29 32 public class TabChangeListenerTag extends TagSupport { 33 36 private static final long serialVersionUID = -6903749011638483023L; 37 40 private String type = null; 41 42 45 public TabChangeListenerTag() { 46 47 } 48 49 54 public void setType(String type) { 55 56 this.type = type; 57 } 58 59 63 public int doStartTag() throws JspException { 64 65 if (type == null) { 66 throw new JspException ("type attribute not set"); 67 } 68 69 UIComponentTag componentTag = 71 UIComponentTag.getParentUIComponentTag(pageContext); 72 if (componentTag == null) { 73 throw new JspException ( 74 "TabChangeListenerTag has no UIComponentTag ancestor"); 75 } 76 77 if (componentTag.getCreated()) { 78 UIComponent component = componentTag.getComponentInstance(); 80 if (component instanceof PanelTabSet) { 81 String className; 82 if (UIComponentTag.isValueReference(type)) { 83 FacesContext facesContext = 84 FacesContext.getCurrentInstance(); 85 ValueBinding valueBinding = facesContext.getApplication() 86 .createValueBinding(type); 87 className = (String ) valueBinding.getValue(facesContext); 88 } else { 89 className = type; 90 } 91 TabChangeListener listener = 92 (TabChangeListener) CustomComponentUtils 93 .newInstance(className); 94 ((PanelTabSet) component).addTabChangeListener(listener); 95 } else { 96 throw new JspException ("Component " + component.getId() + 97 " is no PanelTabSet"); 98 } 99 } 100 101 return Tag.SKIP_BODY; 102 } 103 } 104 | Popular Tags |