public int doStartTag() throws JspException {
if (type == null)
{
throw new JspException("type attribute not set");
}
//Find parent UIComponentTag
UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
if (componentTag == null)
{
throw new JspException("TabChangeListenerTag has no UIComponentTag ancestor");
}
if (componentTag.getCreated())
{
//Component was just created, so we add the Listener
UIComponent component = componentTag.getComponentInstance();
if (component instanceof HtmlPanelTabbedPane)
{
Object listenerRef = type;
if (UIComponentTag.isValueReference(type))
{
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueBinding valueBinding = facesContext.getApplication().createValueBinding(type);
listenerRef = valueBinding.getValue(facesContext);
}
if(listenerRef instanceof String)
{
String className = (String) listenerRef;
TabChangeListener listener = (TabChangeListener) ClassUtils.newInstance(className);
((HtmlPanelTabbedPane) component).addTabChangeListener(listener);
}
else if(listenerRef instanceof TabChangeListener)
{
TabChangeListener listener = (TabChangeListener) listenerRef;
((HtmlPanelTabbedPane) component).addTabChangeListener(listener);
}
else
throw new JspException("type is neither a 'String' nor a value-binding to a 'String' or a 'TabChangeListener' instance.");
}
else
{
throw new JspException("Component " + component.getId() + " is no HtmlPanelTabbedPane");
}
}
return Tag.SKIP_BODY;
}
|