Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

See this.

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

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

like image 210
Xiè Jìléi Avatar asked May 17 '11 08:05

Xiè Jìléi


People also ask

What is an h head?

HtmlHead is a UIOutput that renders a <head> element for webapps, but not for portlets. In the case of portlets, the presence of h:head informs the JSF portlet bridge that JSF resources with target="head" should be included in the <head> element rendered by the portal.

What is H in JSF?

JSF <h:form> Tag The <h:form> tag represents an input form. It includes child components that can contain data which is either presented to the user or submitted with the form. It can also include HTML markup to lay out the components on the page.

What is Facelets in JSF?

Facelets is a powerful but lightweight page declaration language that is used to build JavaServer Faces views using HTML style templates and to build component trees. Facelets features include the following: Use of XHTML for creating web pages.


2 Answers

  • The <head> tag is a HTML tag, which defines the head of the HTML page (this is where you define metadata, or include the resources such as JavaScript or CSS for example).
  • The <h:head> is a JSF tag (introduced with JSF 2.0) that handles the <head> part of your page. The interest of having such JSF tag is that this head becomes part of your JSF components tree, and thus, you can manipulate it in your Java code.

Regarding the <head> incompatibility with Primefaces, I don't see why it happens. Facelets introduced in JSF 1.x the ability to mix HTML code and JSF (XHTML) code, and you should not have any trouble to insert a HTML <head> tag in your page, even if you use Primefaces. Facelets is natively integrated with JSF 2.x.

like image 42
Romain Linsolas Avatar answered Oct 06 '22 07:10

Romain Linsolas


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.

like image 174
BalusC Avatar answered Oct 06 '22 07:10

BalusC