What's the difference between <h:head> and <head> in Java Facelets?

Xi&#232; J&#236;l&#233;i picture Xiè Jìléi · May 17, 2011 · Viewed 14.9k times · Source

See this.

When and why to use <h:head>, instead of <head>?

I've seen Primefaces won't work with <head>, though.

Answer

BalusC picture BalusC · May 18, 2011

The <h:head> is a JSF component which provides a hook to programmatically include JavaScript and CSS resources in the generated HTML <head>. PrimeFaces uses it to include the necessary JS/CSS code for the Ajax works and fancy look'n'feel.

As a test, create a page with a <h:head> and a PrimeFaces component, open the page in the webbrowser and check the generated HTML source by rightclick - View Source. You'll see that several JSF and PrimeFaces specific JS/CSS files are been added. Now replace <h:head> by <head> and check the generated HTML source once again, you'll see nothing this time.