JSF 2 h body

JSF 2 h body


Posted in : Java Posted on : July 31, 2012 at 10:52 AM Comments : [ 0 ]

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

JSF 2 h body

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

<h:body> tag of JSF html tag library is rendered to the HTML <body> element. This tag defines the body part of document that may contains all the JSF tags for example <f:view>, <f:converter>, <h:button>, <h:link> etc.

Attributes of JSF 2 h body

  • dir : This is not a required 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 not a required attribute. This attribute is used to specify the language code for the component.
  • onclick : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on clicking of mouse pointer button over the element a Javascript code will be executed.
  • ondblclick : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on the clicking of mouse pointer button double across the element a Javascript code will be executed.
  • onkeydown : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on the key pressing down across the current element a Javascript code will be executed.
  • onkeypress : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on the key is pressed and released across the current element a Javascript code is executed.
  • onkeyup : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on the key is released across the current element a Javascript code is executed.
  • onload : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on the loading (by the user agent) of window or all frames within a frameset is finished a Javascript code is executed.
     
  • onmousedown : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on the pressing down of the mouse pointer button over the current element a Javascript code is executed.
  • onmousemove : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on moving of the mouse pointer inside the current element a Javascript code is executed.
  • onmouseout : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on moving away of the mouse pointer form the current element a Javascript code is executed.
  • onmouseover : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on moving of the mouse pointer to on the current element a Javascript code is executed.
  • onmouseup : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on releasing of the mouse pointer over the current element a Javascript code is executed.
  • onunload : This is not a required attribute. This attribute evaluates to a java.lang.String value, specifies that on removing of the document (by the user agent) from a window or frame.
  • style : This is not a required attribute. This attribute evaluates to a java.lang.String value, which specifies that the CSS style will be applied to this component when rendered.
  • styleClass : This is not a required attribute. This attribute evaluates to a java.lang.String value specifies the applicable CSS style space-separated list to applied at the time of rendering. "class" attribute must be used to pass this value.
  • title : This is not a required attribute. This attribute evaluates to a java.lang.String value specifies the text information of the component as a tooltip when the mouse pointer is hover over current element.
  • binding : This is not a required attribute. This attribute evaluates to a javax.faces.component.UIComponent specified for linking the component with the property of backing bean.

Example :

An example is being given here will demonstrate you about how to use the JSF <h:body> tag in JSF applications. In this example I have created a JSF page named jsfBody.xhtml where I have used this tag. You can see it's rendered view in the view page source code as the HTML code.

Directory Structure

jsfBody.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">

<head>
<title>JSF 2 h body Example</title>
</head>
<h:body>
<f:view>
<p>Body part of the Document</p>
</f:view>
</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>jsfHBody</display-name>
<welcome-file-list>
<welcome-file>jsfBody.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/jsfHBody/jsfBody.xhtml in the address bar of the web browser.

Output :

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

In the HTML code you can see that <body> tag in place of <h:body> 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 body Example</title>
</head><body>
<p><b>Body part of the Document</b></p></body>
</html>
Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics