JSF 2 h head

JSF 2 h head


Posted in : Java Posted on : July 31, 2012 at 11:13 AM Comments : [ 0 ]

In this tutorial you will learn about the JSF 2 html head tag.

JSF 2 h head

In this tutorial you will learn about the JSF 2 html head tag.

<h:head> tag of JSF 2 html tag library is render the instruction for <head> element. As the <head> tag in HTML contains the head elements such as title (required element ), metadata, includes the resources (CSS, Javascript etc.), etc. So in the JSF 2 <h:head> tag is introduced that provides the facility to handle the HTML <head> part of page programmatically. When this tag is used it becomes the part of the JSF components tree, and that's why it can be manipulated in the further Java code.

Attributes of JSF 2 h head tag

  • dir : This is an optional attribute. This attribute evaluates to the java.lang.String value that suggests the direction for the text which doesn't inherit the property of maintaining a direction. The allowable values are "LTR (Left-to-Right)" and "RTL (Right-to-Left)".
  • lang : This is an optional attribute. This attribute is used to specify the language code for the component.
  • binding : This is an optional attribute. This attribute evaluates to a javax.faces.component.UIComponent specified for linking the component with the property of backing bean.

Example :

A very simple example is being given here which will demonstrate you about the use of JSF 2 h head tag. In this example I have created the JSF view page where I have used this tag and inside the <h:head> tag I have used the <title> tag which will specify the title of the JSF view page.

Directory Structure

jsfHeadExample.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">

<h:head>
<title>JSF 2 h head Example</title>
</h:head>
<h:body>
<h1>JSF 2 html head tag Example</h1>
</h:body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>jsfHHead</display-name>
<welcome-file-list>
<welcome-file>jsfHeadExample.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>

How To Run

After copying the above code paste them to the respective files or by downloading the code from Download Source Code start your web server and then use the following link http://localhost:8181/jsfHHead/jsfHeadExample.xhtml in the address bar of the web browser.

Output :

When you will execute the above example you will get the output as follows :

And when you will see the HTML source code you can see that the JSF <h:head> tag is rendered to the HTML <head> tag.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JSF 2 h head Example</title>
</head>
<body>
<h1>JSF 2 html head tag Example</h1>
</body>
</html>
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics