background image

Value-Change Event

<< Referencing a Method | Using Custom Objects >>
<< Referencing a Method | Using Custom Objects >>

Value-Change Event

"Writing a Method to Handle an Action Event" on page 406
describes how to implement a
method that handles an action event.
Referencing a Method That Performs Validation
If the input of one of the components on your page is validated by a backing bean method, you
refer to the method from the component's tag using the validator attribute.
The Coffee Break application includes a method that performs validation of the email input
component on the checkoutForm.jsp page. Here is the tag corresponding to this component:
<h:inputText id=
"email" value="#{checkoutFormBean.email}"
size=
"25" maxlength="125"
validator=
"#{checkoutFormBean.validateEmail}"/>
This tag references the validate method described in
"Writing a Method to Perform
Validation" on page 406
using a method expression.
Referencing a Method That Handles a Value-change
Event
If you want a component on your page to generate a value-change event and you want that
event to be handled by a backing bean method, you refer to the method using the component's
valueChangeListener
attribute.
The name component on the bookcashier.jsp page of the Duke's Bookstore application
references a ValueChangeListener implementation that handles the event of a user entering a
name in the name input field:
<h:inputText
id=
"name"
size=
"50"
value=
"#{cashier.name}"
required=
"true">
<f:valueChangeListener type=
"listeners.NameChanged" />
</h:inputText>
For illustration,
"Writing a Method to Handle a Value-Change Event" on page 407
describes
how to implement this listener with a backing bean method instead of a listener
implementation class. To refer to this backing bean method, the tag uses the
valueChangeListener
attribute:
<h:inputText
id=
"name"
size=
"50"
Referencing a Backing Bean Method
The Java EE 5 Tutorial · September 2007
372