tomahawk.taglib.xml

<tag>
      <tag-name>tabChangeListener</tag-name>
      <handler-class>facelets.TabChangeListenerHandler</handler-class>
</tag>

TabChangeListenerHandler.java

import java.io.IOException;

import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;

import org.apache.myfaces.custom.tabbedpane.HtmlPanelTabbedPane;
import org.apache.myfaces.custom.tabbedpane.TabChangeListener;
import org.apache.myfaces.shared_tomahawk.util.ClassUtils;

import com.sun.facelets.FaceletContext;
import com.sun.facelets.FaceletException;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.tag.TagConfig;
import com.sun.facelets.tag.TagHandler;

/**
 * Tag Handler for tabChangeListener tag
 */
public class TabChangeListenerHandler extends TagHandler {
	private final TagAttribute	type;

	/**
	 * @param tagConfig
	 */
	public TabChangeListenerHandler(TagConfig tagConfig) {
		super(tagConfig);
		type = getRequiredAttribute("type");
	}

	/* (non-Javadoc)
	 * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, javax.faces.component.UIComponent)
	 */
	public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException, FacesException, FaceletException, ELException {
		// only process if parent was just created
		if (parent.getParent() == null) {
			if (parent instanceof HtmlPanelTabbedPane) {
				String className;
	            if (!type.isLiteral()) {
	               className = type.getValue();
	            } else {
	               className = type.getValue(faceletContext);
	            }
	            TabChangeListener listener = (TabChangeListener) ClassUtils.newInstance(className);
		        ((HtmlPanelTabbedPane)parent).addTabChangeListener(listener);
			} else {
				throw new FacesException("Component is noHtmlPanelTabbedPane children");
	        }
		}
	}
}
  • No labels