myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "TagHandler" by SebastienLever
Date Wed, 14 Feb 2007 12:50:32 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by SebastienLever:
http://wiki.apache.org/myfaces/TagHandler

New page:
##language:en
== TagHandler ==
Using facelets, you need to define each used tag in your tomahawk.taglib.xml file.

If it concerns a JSP tag, you'll have to write a facelets tag handler for it.

here are existing tag handlers implementations

=== tabChangeListener ===
__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");
	        }
		}
	}
}
}}}

Mime
View raw message