In particular, a "return ..." has very different semantics in both cases.
Consider this code:
<p:commandLink action="#{bean.method}" onstart="return func()" ...>
If "func()" return false, this code will abort the AJAX request and bean.method() won't get called.
If "func()" returns true, the AJAX request processes.
If you replace onstart with onclick, the AJAX request will abort even if func() returns true.
That's because the Primefaces puts the code to generate the AJAX request in the onclick handler, pre-pending your code from the p:commandLink onclick before it. If your code returns, the AJAX request never gets sent.
本文详细解释了在PrimeFaces框架中,AJAX回调的onstart与onclick事件的区别。当使用onstart时,如果回调函数返回false,则会阻止AJAX请求并取消调用后端方法;而onclick即使返回true,也可能阻止AJAX请求。
2880

被折叠的 条评论
为什么被折叠?



