public void apply(FaceletContext ctx, UIComponent parent)
throws IOException, FacesException, FaceletException, ELException {
if (parent instanceof ActionSource) {
// only process if parent was just created
if (parent.getParent() == null) {
ActionSource src = (ActionSource) parent;
ActionListener listener = null;
ValueExpression ve = null;
if (this.binding != null) {
ve = this.binding.getValueExpression(ctx,
ActionListener.class);
listener = (ActionListener) ve.getValue(ctx);
}
if (listener == null) {
try {
listener = (ActionListener) listenerType.newInstance();
} catch (Exception e) {
throw new TagAttributeException(this.tag, this.type, e.getCause());
}
if (ve != null) {
ve.setValue(ctx, ve);
}
}
src.addActionListener(listener);
}
} else {
throw new TagException(this.tag,
"Parent is not of type ActionSource, type is: " + parent);
}