Faces uses JavaServer Pages (JSPs) as view components. They require several special-purpose jsf taglibs. Among other functions, the taglib simplify the HTML specification of input components, such as TextFields, and automatically transfer data from them to a ManagedBean associated with the page.
Example
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%!String projectName = jbs.eb2cuser.util.Context.getProjectName();%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <LINK href='/<%= projectName %>/theme/Master.css' rel='stylesheet' type='text/css'> <title>eb2c login</title> </head> <body> <center> <h1>Welcome to MyStore</h1> <h3>Please login</h3> </center> <f:view> <h:form id="loginForm"> <center> <h:panelGrid columns="3" columnClasses="COLUMNLABELRIGHT,,"> <!-- Custom validator class, with constructed message --> <h:outputLabel value="Email:" for="email" /> <h:inputText id="email" value="#{managedBeanUser.email}" required="true" > <f:validator validatorId="custom.validateEmail" /> </h:inputText> <h:message for="email" /> <!-- Custom message --> <h:outputLabel value="Password: " for="password" /> <h:inputSecret id="password" value="#{managedBeanUser.password}" required="true" requiredMessage="#{customMessage['emptyField']}" /> <h:message for="password" /> <h:outputLabel value="" /> <h:commandButton id="userAction" action="#{managedBeanUser.actionLogin}" value="Login" style="background-color: rgb(224, 250, 226)"/> <h:outputLabel value="" /> <h:outputLabel value="Messages:" for="message" /> <h:inputTextarea id="message" value="#{managedBeanUser.message}" rows="4" cols="25" /> <h:message for="message" /> </h:panelGrid> </center> </h:form> </f:view> </body> </html>
Comments
Taglibs
f:view tag
h:form tag
h:panelGrid tag
h:inputText tag
h:inputSecret tag
h:commandButton tag
h:textAreaa tag