[英]f:ajax restricting the listener method call based on onevent return value
How do i check for Onevent javascript function whether it returns true or False ? 我如何检查Onevent javascript函数是否返回true或False? Because basically what iam trying to do is to restrict the listener method call based on the Javascript return value .
因为从根本上来说,iam试图做的是基于Javascript返回值来限制侦听器方法的调用。
The following code returns syntax error in Firebug . 以下代码在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 :) 所以我该如何确定返回值以及基于lister方法应该触发的结果。
The onevent
attribute must specify a JS function reference name, not a whole JS script. onevent
属性必须指定JS函数引用名称,而不是整个JS脚本。 The proper usage of the onevent
attribute is onevent
属性的正确用法是
<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. onevent
应该仅引用将调用3次的侦听器函数:一次在发送ajax请求之前,一次在到达ajax响应之后,一次在基于ajax响应更新HTML DOM之后。 For proper real world usage examples, see among others Proccess onclick function after ajax call <f:ajax> and Disable/enable commandbutton on ajax event . 有关正确的实际用法示例,请参见ajax调用<f:ajax>后的Proccess onclick函数和ajax event的Disable / enable命令按钮 。
Just use the parent component's onXXX
attribute instead (where XXX
is exactly that <f:ajax event>
you'd like to hook on). 只需使用父组件的
onXXX
属性即可(其中XXX
正是您要挂接的<f:ajax event>
)。 Eg asusming that it's an <h:inputText>
: 例如,假设它是
<h:inputText>
:
<h:inputText ... onkeyup="return validatePageNumber(event)">
<f:ajax event="keyup" render="@form" />
</h:inputText>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.