Jim Driscoll's Blog

Notes on Technology and the Web

Including scripts in JSF 2 Ajax requests

leave a comment »

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.

(This article originally published on my java.net blog on July 18, 2009.)

Advertisements

Written by jamesgdriscoll

February 9, 2010 at 9:04 PM

Posted in ajax, JSF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: