HTML and CSS Reference
In-Depth Information
Listing 1-6.
The index.xhtml Page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="
http://www.w3.org/1999/xhtml
"
xmlns:ui="
http://java.sun.com/jsf/facelets
"
xmlns:h="
http://java.sun.com/jsf/html
"
>
<ui:composition template="/WEB-INF/templates/simple.xhtml">
<ui:define name="title">
#{bundle['application.loginpage.title']}
</ui:define>
<ui:define name="content">
<h:form>
<h:panelGrid columns="3">
<h:outputText value="#{bundle['user.name']}"></h:outputText>
<h:inputText id="userName"
value="#{user.name}"
required="true"
requiredMessage="#{bundle['user.name.validation']}">
</h:inputText>
<h:message for="userName" styleClass="errorMessage"/>
<h:outputText value="#{bundle['user.password']}"></h:outputText>
<h:inputSecret id="password"
value="#{user.password}"
required="true"
requiredMessage="#{bundle['user.password.validation']}">
</h:inputSecret>
<h:message for="password" styleClass="errorMessage"/>
</h:panelGrid>
<h:commandButton value="#{bundle['application.login']}" action="welcome">
</h:commandButton> <br/><br/>
</h:form>
</ui:define>
</ui:composition>
</html>
In order to include the
simple.xhtml
template page in the
index.xhtml
page (or any other XHTML page), the
<ui:composition>
tag is used, specifying its
template
attribute with the relative path of the template page. The
<ui:composition>
tag includes
<ui:define>
tags. The
<ui:define>
tag is used for overriding the template content
that is defined by the
<ui:insert>
tag if the tags are matched using the
name
attribute.
In the
index.xhtml
page, the
"title"
and the
"content"
of the template are overridden with the page title and
the page content. The page content includes an
<h:form>
tag that is required for all the JSF input components which
participate in the form submission.
In order to make the internal layout of the form, the
<h:panelGrid>
tag is used. The
<h:panelGrid>
tag is a layout
container that renders the JSF components in a grid of rows and columns. The
<h:panelGrid>
tag has a
columns