JSF 2 facet Tag

JSF 2 facet Tag


Posted in : Java Posted on : June 7, 2012 at 7:02 PM Comments : [ 0 ]

In this tutorial you will learn about the JSF core tag .

JSF 2 facet Tag

In this tutorial you will learn about the JSF core tag <f:facet>.

JSF provides the facility to assigned name facet (a distinct element by giving name) on the closest parent UIComponent. This feature is provided by the tag <f:facet> of JSF core tag library. This tag uses its attribute name to create the name of facet.

Attributes of f:facet

  • name : This is a required attribute that is used for creating the name of the facet.

Example :

Here an example is being given will demonstrate about how can you use the JSF core <f:facet> tag in your application. To show how to use JSF f facet tag in an application I have also created an application and use this tag in this application. However, more other tags are also used but we shall focus on the use of <f:facet> tag. At first I have created a New Web Dynamic Project in Eclipse and configured JSF facilities, then created a folder named jsfPages in Web Content folder Eclipse for creating JSF pages. In this folder I have created a XHTML page as a JSF page and named it by namedFacet.xhtml. At the top of this page XHTML DTD is defined in the next line the <html> tag defines the W3 standard for XHTML and JSF's XML syntax for the core and html tag libraries. In next line the tag <head> and <body> are the HTML tags. Now from the next line JSF tags are used, among of these tags I have used the <f:facet name="header">  and <f:facet name="footer"> tag inside the <h:panelGrid>, after execution which HTML source code will as <thead><tr><th colspan="3" scope="colgroup">Employee Record</th></tr></thead> and <tfoot><tr><td colspan="3">* :- Part time developer</td></tr></tfoot> respectively. Then in the auto generated web.xml file changed the welcome file-list as <welcome-file-list><welcome-file>jsfPages/namedFacet.xhtml</welcome-file></welcome-file-list>.

Directory Structure of this example

namedFacet.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 f facet Tag Example</title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid border="1" columns="3" rules="all">
<f:facet name="header">
<h:outputText value="Employee Record"/>
</f:facet>
<h:outputText value="EmpId" />
<h:outputText value="Name" />
<h:outputText value="Department" />
<h:outputText value="1" />
<h:outputText value="ABC*" />
<h:outputText value="Development" />
<f:facet name="footer">
<h:panelGroup>
<h:outputText value="*" />
<h:outputText value=" :- " />
<h:outputText
value="Part time developer" />
</h:panelGroup>
</f:facet>
</h:panelGrid> 
</h:form>
</f:view>
</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>jsfFacet</display-name>
<welcome-file-list>
<welcome-file>jsfPages/namedFacet.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 this example

At first Start your server then Right Click on your project and select Run As -> Run On Server.

Then URL will as follows : http://localhost:8080/jsfFacet/jsfPages/namedFacet.jsf

Output :

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

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics