public void apply(FaceletContext ctx, UIComponent parent)
throws IOException, FacesException, FaceletException, ELException {
if (parent instanceof AjaxSource) {
// only process if parent was just created
if (parent.getParent() == null) {
AjaxSource src = (AjaxSource) parent;
AjaxListener listener = null;
ValueExpression ve = null;
if (this.binding != null) {
ve = this.binding.getValueExpression(ctx,
AjaxListener.class);
// TODO - handle both JSF 1.2/1.1 cases.
listener = new AjaxListenerHelper(new LegacyValueBinding(ve));
}
if (listener == null) {
try {
listener = (AjaxListener) listenerType.newInstance();
} catch (Exception e) {
throw new TagAttributeException(this.tag, this.type, e.getCause());
}
if (ve != null) {
ve.setValue(ctx, ve);
}
}
src.addAjaxListener(listener);
}
} else {
throw new TagException(this.tag, Messages.getMessage(Messages.NOT_PARENT_AJAX_COMPONENT_ERROR, parent));
}
}