Primefaces AJAX callbacks: onstart vs. onclick

前端之家收集整理的这篇文章主要介绍了Primefaces AJAX callbacks: onstart vs. onclick前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Primefaces AJAX callbacks: onstart vs. onclick

I just learned the hard way that onstart and onclick are not the same thing.

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.

http://wrschneider.blogspot.com/2012/01/primefaces-ajax-callbacks-onstart-vs.html
原文链接:https://www.f2er.com/ajax/166072.html

猜你在找的Ajax相关文章