How do i check for Onevent javascript function whether it returns true or False ? Because basically what iam trying to do is to restrict the listener method call based on the Javascript return value .
The following code returns syntax error in Firebug .
<f:ajax event="keyup" render="@form" onevent="return validatePageNumber(event);" listener="#{bean.listenerMethod}"/>
So How can i determine return value and based onthat the lister method should fire .Thanks in advance :)
How do i check for Onevent javascript function whether it returns true or False ? Because basically what iam trying to do is to restrict the listener method call based on the Javascript return value .
The following code returns syntax error in Firebug .
<f:ajax event="keyup" render="@form" onevent="return validatePageNumber(event);" listener="#{bean.listenerMethod}"/>
So How can i determine return value and based onthat the lister method should fire .Thanks in advance :)
Share Improve this question edited Feb 26, 2013 at 15:26 BalusC 1.1m376 gold badges3.7k silver badges3.6k bronze badges asked Feb 26, 2013 at 14:41 Muthu RamanMuthu Raman 1542 silver badges13 bronze badges 1- Bind you ponent's desired behaviour with "if (!validatePageNumber()) return false;" and enclose within your ponent tag the f:ajax tag. That way you'll be able to intercept the execution basing on your JavaScript code. – skuntsel Commented Feb 26, 2013 at 15:08
1 Answer
Reset to default 6The onevent
attribute must specify a JS function reference name, not a whole JS script. The proper usage of the onevent
attribute is
<f:ajax ... onevent="functionName" />
(yes, without parentheses!)
with
function functionName(data) {
alert(data.status); // Will show 3 times.
}
However, it's clearly the wrong tool for the purpose you had in mind. The onevent
should merely reference a listener function which would be invoked 3 times: one before the ajax request is sent, one after the ajax response is arrived, one after the HTML DOM is updated based on ajax response. For proper real world usage examples, see among others Proccess onclick function after ajax call <f:ajax> and Disable/enable mandbutton on ajax event.
Just use the parent ponent's onXXX
attribute instead (where XXX
is exactly that <f:ajax event>
you'd like to hook on). E.g. asusming that it's an <h:inputText>
:
<h:inputText ... onkeyup="return validatePageNumber(event)">
<f:ajax event="keyup" render="@form" />
</h:inputText>