The index.xhtml page is the first page shown when the user enters the application url into their browser. It has a form with name and password input text fields and a "Login" button.
<?xml version="1.0" encoding="UTF-8"?> <!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"> <h:head> <title>Welcome</title> </h:head> <h:body> <h:form> <h3>Please enter your name and password.</h3> <table> <tr> <td>Name:</td> <td><h:inputText value="#{user.name}"/></td> </tr> <tr> <td>Password:</td> <td><h:inputSecret value="#{user.password}"/></td> </tr> </table> <p><h:commandButton value="Login" action="welcome"/></p> </h:form> </h:body> </html>
Two namespace declarations in the html tag declare the tag namespaces used in the page: a global namespace and a namespace that uses a h: prefix. The latter is part of the JSF framework.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
The connection to the user bean is made in the two following lines. When the "Login" button is clicked the setName() and setPassword() methods of the user bean are invoked on the server.
<td><h:inputText value="#{user.name}"/></td>
<td><h:inputSecret value="#{user.password}"/></td>