background image

The inputText Tag

<< UIInput and UIOutput Tags | The outputLabel Tag >>
<< UIInput and UIOutput Tags | The outputLabel Tag >>

The inputText Tag

lang
: Specifies the code for the language used in the rendered markup, such as en_US.
required
: Takes a boolean value that indicates whether or not the user must enter a value in
this component.
requiredMessage
: Specifies an error message to display when the user does not enter a value
into the component.
validator
: Identifies a method expression pointing to a backing bean method that
performs validation on the component's data. See
"Referencing a Method That Performs
Validation" on page 372
for an example of using the validator tag.
validatorMessage
: Specifies an error message to display when the validator registered on
the component fails to validate the component's local value.
valueChangeListener
: Identifies a method expression that points to a backing bean
method that handles the event of entering a value in this component. See
"Referencing a
Method That Handles a Value-change Event" on page 372
for an example of using
valueChangeListener
.
The UIOutput component tags support the converter tag attribute in addition to those listed in
"Adding UI Components to a Page Using the HTML Component Tags" on page 327
. The rest of
this section explains how to use selected tags listed in
Table 11­3
. The other tags are written in a
similar way.
Rendering a Text Field with the inputText Tag
The inputText tag is used to display a text field. It represents the combination of a Text
renderer and a UIInput component. A similar tag, the outputText tag, displays a read-only,
single-line string. It represents the combination of a Text renderer and a UIOutput component.
This section shows you how to use the inputText tag. The outputText tag is written in a similar
way.
Here is an example of an inputText tag from the bookcashier.jsp page:
<h:inputText id=
"name" label="Customer Name" size="50"
value=
"#{cashier.name}"
required=
"true"
requiredMessage=
"#{customMessages.CustomerName}">
<f:valueChangeListener
type=
"com.sun.bookstore6.listeners.NameChanged" />
</h:inputText>
The label attribute specifies a user-friendly name that will be used in the substitution
parameters of error messages displayed for this component.
The value attribute refers to the name property of CashierBean. This property holds the data
for the name component. After the user submits the form, the value of the name property in
CashierBean
will be set to the text entered in the field corresponding to this tag.
Adding UI Components to a Page Using the HTML Component Tags
The Java EE 5 Tutorial · September 2007
332