Skip to main content

Including scripts in JSF 2 Ajax requests

Posted by driscoll on July 18, 2009 at 3:39 PM PDT

I'd wanted to blog some time ago about including scripts in your JSF ajax requests, but Hazem Saleh beat me to it. Hazem is the creator of the nifty Google Maps component for JSF, gmaps4jsf.

So, go and follow the link, but I'll just add three short comments to Hazem's blog:

  • In many popular ajax solutions for JSF, <script> tags were simply interpreted in place. This is not, for whatever reason, part of the JSF spec right now - so you'll have to use one of the two ways that Hazem describes, in order for it to be a portable solution.
  • The first solution Hazem notes uses the event system for JSF client side - it simply adds an event listener that's called every time a page is updated, and calls the eval for any included scripts.
  • The second solution is the "preferred" way that is specified in the spec - simply return the script you want to execute as part of the xml that goes to the client.

Hope this note helps someone trying to execute an arbitrary script on a JSF client page.

Related Topics >>