posted 15 years ago
Yup. The javascript is performed in the browser by the browser. And since the browser submit function is actually requesting a new page, the javascript is likely to be gone by the time the new page loads. Even if it's just the same page reloading, all the javascripts from the previous copy of the page have been invoked before the submit is done. That's HTML, and in JSF, HTML rules still apply.
On the other hand, if you use an AJAX-style control like the RichFaces command button, the click mechanism can do a partial page request - which is in reality a complete "page" request, but with JavaScript taking the returned data and updating the current page DOM instead of displaying a fresh page. Because the displayed page isn't being replaced - only data is being fetched - it's possible to invoke a javascript function AFTER the AJAX request is complete.
Correction: The "onclick" gets done before the action. One of the things that onclick's can do is abort the action entirely.
[ May 01, 2008: Message edited by: Tim Holloway ]
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.