- 

Available since OmniFaces 1.0

The <o:methodParam> is a tag handler that can be used to pass a method expression as attribute into a Facelets tag. By default this is not possible, and the expression that's intended to be a method expression will be created and made available as a value expression.

This handler wraps a value expression that's actually a method expression by another value expression that returns a method expression that gets the value of first value expression, which as "side-effect" executes the original method expression. This somewhat over-the-top chain of wrapping is done so a method expression can be passed as attribute into a Facelet tag.

Demo

This page demonstrates the passing of an EL reference to a method to a Facelets tag in a variety of different ways. Note that the <demo:xxx> tags in the example are purely for demonstration, it should represent your own custom Facelets tag.

  • Action invoked: false
  • Listener invoked: false
  • Lisitener with event invoked: false

Actions

Passing method with zero arguments

Passing method with zero arguments but explicit parenthesis

Passing method with 1 view provided argument:

Passing method to second bean with 1 view provided argument:

Listeners

Passing listener method with zero arguments (always needs trick to pass!)

Passing listener method with zero arguments but explicit parenthesis (needs trick on older EL impl. like JBoss 6, not needed on AS 7)

Passing listener method with 1 view provided argument:

Passing listener method with declared event parameter, no provided arguments

Direct bindings

Direct binding (no method passing) with zero arguments:

Demo source code
<p>
    This page demonstrates the passing of an EL reference to a method to a Facelets tag in a variety of 
    different ways. Note that the <code>&lt;demo:xxx&gt;</code> tags in the example are purely for demonstration,
    it should represent your own custom Facelets tag.
</p>
<h:form>
    <ul>
        <li>Action invoked: #{methodParamBean.actionInvoked}</li>
        <li>Listener invoked: #{methodParamBean.listenerInvoked}</li>
        <li>Lisitener with event invoked: #{methodParamBean.listenerWithEventInvoked}</li>
    </ul>

    <h3>Actions</h3>
    <p>
        Passing method with zero arguments
        <demo:actionmethod action="#{methodParamBean.doAction}" />
    </p>
    <p>
        Passing method with zero arguments but explicit parenthesis
        <demo:actionmethod action="#{methodParamBean.doAction()}" />
    </p>
    <p>
        Passing method with 1 view provided argument: 
        <demo:actionmethod action="#{methodParamBean.doActionWithParam('test')}" />
    </p>
    <p>
        Passing method to second bean with 1 view provided argument: 
        <demo:actionmethod action="#{methodParamBean.bean.doActionWithParam('test')}" />
    </p>

    <h3>Listeners</h3>
    <p>
        Passing listener method with zero arguments
        (always needs trick to pass!)
        <demo:actionlistenertrick listener="#{methodParamBean.actionListener}" />
    </p>
    <p>
        Passing listener method with zero arguments but explicit parenthesis
        (needs trick on older EL impl. like JBoss 6, not needed on AS 7)
        <demo:actionlistenertrick listener="#{methodParamBean.actionListener()}" />
    </p>
    <p>
        Passing listener method with 1 view provided argument: 
        <demo:actionlistener listener="#{methodParamBean.actionListenerWithParam('test')}" />
    </p>
    <p>
        Passing listener method with declared event parameter, no provided arguments
        <demo:actionlistener listener="#{methodParamBean.actionListenerWithClientParam}" />
    </p>

    <h3>Direct bindings</h3>
    <p>
        Direct binding (no method passing) with zero arguments: 
        <h:commandButton value="test" action="#{methodParamBean.doAction()}" />
    </p>
 </h:form>
Documentation & Sources