public void apply(FaceletContext faceletContext, UIComponent parent)
throws IOException, FacesException, ELException {
if (parent instanceof TabChangeSource) {
// only process if parent was just created
if (parent.getParent() == null) {
TabChangeSource changeSource = (TabChangeSource) parent;
TabChangeListener listener = null;
ValueExpression valueExpression = null;
if (binding != null) {
valueExpression = binding.getValueExpression(faceletContext, TabChangeListener.class);
listener = (TabChangeListener) valueExpression.getValue(faceletContext);
}
if (listener == null) {
try {
listener = (TabChangeListener) listenerType.newInstance();
} catch (Exception e) {
throw new TagAttributeException(tag, type, e.getCause());
}
if (valueExpression != null) {
valueExpression.setValue(faceletContext, listener);
}
}
if (valueExpression != null) {
if (FacesVersion.supports12()) {
FacesUtils.addBindingOrExpressionTabChangeListener(changeSource, type.getValue(), valueExpression);
} else {
FacesUtils.addBindingOrExpressionTabChangeListener(changeSource, type.getValue(),
new LegacyValueBinding(valueExpression));
}
} else {
changeSource.addTabChangeListener(listener);
}
}
} else {
throw new TagException(tag, "Parent is not of type TabChangeSource, type is: " + parent);
}