• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

h:commandbutton javascript

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was always under the impression the 'onclick' gets performed after the action. This isn't the case for you?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic