Off-topic: Custom compoent that places scripts in <head> ?

UI Components for JSF
Post Reply
joachimhs
Posts: 1
Joined: 23 Mar 2009, 22:41

23 Mar 2009, 22:43

Hello,

I wish to create a custom component that is a wrapper for a javascript library. I am able to get things working, but not with Ajax. I had originally rendered the <script src=""> tags once for each request, but since ajax updates the component, the libraries gets loaded multiple times.

I know that PrimeFaces are able to place the script references inside the <head> portion of the page, but looking at the sourcecode I am unable to gather where and how this happens.

I have created a phaselistener that extract the script files from the .JAR file, so that they are available from the Browser with a URL.

Does anyone have a solution or some pointers as to how it is possible for a component library to alter the <head> portion of the page ?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

24 Mar 2009, 12:19

There're couple of ways to enfore a resource to be included only once, one way it the request map trick, when rendering the script tag add a flag to the request scope. When script tag needs to be rendered for the second time, first check if the script is already added using the flag in request map.

Altering head is not easy and may require a filter and response wrapping, tomahawk and richfaces does that but primefaces dont because it has bad effect on performance since html parsing is involved.

JSF 2 has good solutions but for JSF 1.x, there're not many.

In PrimeFaces we advise users to add p:resources component to the head manually. If you have only one component, I'd suggest using the request map trick to ensure the resource is added once and render the script tag inside the body along with the other component output. Until JSF 2:)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 18 guests