×
☰ See All Chapters

JSF Facelets

  • All facelets are saved with xhtml extension, example: “home.xhtml”. 

  • Prior to JSF 2.0, JSP was used as a View Declaration Language for JSF. 

  • From JSF 2.0.  facelets are incorporated into the core JSF specification. 

  • Facelets cannot be rendered directly as a response. 

  • All facelets will be (should be) processed by javax.faces.webapp.FacesServlet 

  • JSF provides 43 tags in two standard JSF tag libraries: 

    1. JSF Core Tags  Library(18 tags)and  

    2. JSF Html Tags Library(25 tags) 

  • Also JSF provides 11 tags for templating. 

  • When we use JSP as a View Declaration Language for JSF, we should to import the tags using <taglib> and syntax is given below. 

jsf-facelets-0
 

Likewise when we use facelets as a View Declaration Language for JSF, we should import the tags using the syntax below.

<anyelement xmlns:prefix="URI" />

This is known as namespace declaration.

We can import more than one library in single tag as

<anyelement xmlns:prefix="URI" xmlns:prefix="URI" xmlns:prefix="URI" />

jsf-facelets-1
 

We can choose any name we want for the prefixes. The convention is f, h and ui for the core, HTML and templating libraries, respectively.

Namespaces for JSF libraries are

    1. JSF Core Tags  Library: <html xmlns:f="https://xmlns.jcp.org/jsf/core" /> 

    2. JSF Html Tags Library: <html xmlns:h="https://xmlns.jcp.org/jsf/html" /> 

    3. JSF templating Tags Library: <html xmlns:ui="https://java.sun.com/jsf/facelets" /> 

We can use tags from the libraries provided by third party vendors like Primefaces , RichFaces… for these tags we have to use namespaces as below:

<html xmlns:p="https://primefaces.org/ui" >

<html xmlns:rich="https://richfaces.org/rich">

All the above namespaces can be written in one single tag as

<html xmlns:ui="https://java.sun.com/jsf/facelets

        xmlns:h="https://xmlns.jcp.org/jsf/html"

        xmlns:f="https://xmlns.jcp.org/jsf/core"

        xmlns:rich="https://richfaces.org/rich

xmlns:p="https://primefaces.org/ui" >

We can also use all non JSF html tags (not from JSF library) in facelets

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="https://www.w3.org/1999/xhtml"

        xmlns:ui="https://java.sun.com/jsf/facelets"

        xmlns:h="https://java.sun.com/jsf/html"

        xmlns:f="https://java.sun.com/jsf/core">

<head>

<title>home page</title>

</head>

 

<h:body style="background-color:yellow">

        <h:form>

                <table border="1">

                        <tr>

                                <td><h:outputText value="Enter Your Name" /></td>

                                <td><h:inputText id="username" value="#{loginBean.strUserName}" /></td>

                        </tr>

 

                        <tr>

                                <td><h:outputText value="Enter Your Password" /></td>

                                <td><h:inputSecret id="password"

                                                value="#{loginBean.strPassword}" /></td>

                        </tr>

 

                        <tr>

                                <td colspan="2"><h:commandButton value="Login"

                                                action="#{loginBean.checkUser}" /></td>

                        </tr>

                </table>

 

        </h:form>

 

</h:body>

</html>

jsf-facelets-2
 

All Chapters
Author