background image

Adding the view and form Tags

<< Creating the Pages | Adding an Image >>
<< Creating the Pages | Adding an Image >>

Adding the view and form Tags

Adding the view and form Tags
All JavaServer Faces pages are represented by a tree of components, called a view. The view tag
represents the root of the view. All JavaServer Faces component tags must be inside of a view
tag, which is defined in the core tag library.
The form tag represents an input form component, which allows the user to input some data
and submit it to the server, usually by clicking a button. All UI component tags that represent
editable components (such as text fields and menus) must be nested inside the form tag. In the
case of the greeting.jsp page, some of the tags contained in the form are outputText,
inputText
, commandButton, and message. You can specify an ID for the form tag. This ID maps
to the associated form UI component on the server.
With the view and form tags added, our page looks like this (minus the HTML and HEAD tags):
<%@ taglib uri=
"http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri=
"http://java.sun.com/jsf/core" prefix="f" %>
<f:view>
<h:form id=
"helloForm1">
</h:form>
</f:view>
Adding a Label Component
The outputText tag represents a label. The greeting.jsp page has two outputText tags. One
of the tags displays the number 0. The other tag displays the number 10:
<h:outputText lang=
"en_US"
value=
"#{UserNumberBean.minimum}"/>
<h:outputText value=
"#{UserNumberBean.maximum}"/>
The value attributes of the tags get the values from the minimum and maximum properties of
UserNumberBean
using value expressions, which are used to reference data stored in other
objects, such as beans. See
"Backing Beans" on page 309
for more information on value
expressions.
With the addition of the outputText tags (along with some static text), the greeting page looks
like the following:
<%@ taglib uri=
"http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri=
"http://java.sun.com/jsf/core" prefix="f" %>
<f:view>
<h:form id=
"helloForm1">
<h2>Hi. My name is Duke. I
'm thinking of a number from
<h:outputText lang=
"en_US"
value=
"#{UserNumberBean.minimum}"/> to
<h:outputText value=
"#{UserNumberBean.maximum}"/>.
A Simple JavaServer Faces Application
Chapter 10 · JavaServer Faces Technology
291