Execute JavaScript before and after the f:ajax listener is invoked

Use onevent attribute. It must point to a callback function reference (so don’t include parentheses!):

<f:ajax ... onevent="functionName" />

Whereby the actual callback function look like this (JSF will provide the argument all by itself):

function functionName(data) {
    var status = data.status; // Can be "begin", "complete" or "success".
    var source = data.source; // The parent HTML DOM element.

    switch (status) {
        case "begin": // Before the ajax request is sent.
            // ...
            break;

        case "complete": // After the ajax response is arrived.
            // ...
            break;

        case "success": // After update of HTML DOM based on ajax response.
            // ...
            break;
    }
}

See also:

Leave a Comment