Optional actionListener for h:commandButton

Here is an implementation of the needed tag handler:

public final class ActionListenerHandler extends TagHandler {

private final static Class[] ACTION_LISTENER_SIG = new Class[]{ActionEvent.class};

private final TagAttribute value;

public ActionListenerHandler(TagConfig config) {
this.value = this.getRequiredAttribute("value");

* (non-Javadoc)
* @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
* javax.faces.component.UIComponent)
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, ELException {
if (parent instanceof ActionSource2) {
if (ComponentSupport.isNew(parent)) {
((ActionSource2) parent).addActionListener(new MethodExpressionActionListener(
value.getMethodExpression(ctx, null, ACTION_LISTENER_SIG)));
} else {
throw new TagException(this.tag,
"Parent is not of type ActionSource2, type is: "
+ parent);


h:commandButton value="#{value}"
c:if test="#{not empty actionListener and actionListener}"
x:actionlistener value="#{bean.actionEvent}"


Popular posts from this blog

Крачка назад във вечния танц

Concatenate rows in Oracle