The onevent
attribute is used to specify a JS function reference name, rather than an entire JS script. The correct way to use the onevent
attribute is
<f:ajax ... onevent="functionName" />
(yes, without parentheses!)
with
function functionName(data) {
alert(data.status); // Will show 3 times.
}
However, it may not be the most suitable tool for the intended purpose. The onevent
attribute should only reference a listener function that will be called 3 times: before the ajax request is sent, after the ajax response is received, and after the HTML DOM is updated based on the ajax response. For real-world usage examples, you can refer to Proccess onclick function after ajax call <f:ajax> and Disable/enable commandbutton on ajax event.
Instead of using the onevent
attribute, you can simply utilize the parent component's onXXX
attribute (where XXX
is the specific <f:ajax event>
you wish to hook onto). For example, if it's an <h:inputText>
:
<h:inputText ... onkeyup="return validatePageNumber(event)">
<f:ajax event="keyup" render="@form" />
</h:inputText>