aspose file tools*
The moose likes JSF and the fly likes h:commandbutton javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "h:commandbutton javascript" Watch "h:commandbutton javascript" New topic
Author

h:commandbutton javascript

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
I have a JSF button that when i click this invokes a javascript


Is there a way to ensure that the Action bean is invoked before the javascript
Leigh Taylor
Greenhorn

Joined: Feb 19, 2008
Posts: 20
I was always under the impression the 'onclick' gets performed after the action. This isn't the case for you?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

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 ]

Customer surveys are for companies who didn't pay proper attention to begin with.
 
 
subject: h:commandbutton javascript