background image

Using Custom Objects

<< Value-Change Event | Using a Custom Converter >>
<< Value-Change Event | Using a Custom Converter >>

Using Custom Objects

value=
"#{cashier.name}"
required=
"true"
valueChangeListener=
"#{cashier.processValueChange}" />
</h:inputText>
The valueChangeListener attribute of this component tag references the
processValueChange
method of CashierBean using a method expression. The
processValueChange
method handles the event of a user entering his name in the input field
rendered by this component.
"Writing a Method to Handle a Value-Change Event" on page 407
describes how to implement a
method that handles a ValueChangeEvent.
Using Custom Objects
As a page author, you might need to use custom converters, validators, or components
packaged with the application on your JSP pages.
A custom converter is applied to a component in one of the following ways:
Reference the converter from the component tag's converter attribute.
Nest a converter tag inside the component's tag and reference the custom converter from
one of the converter tag's attributes.
A custom validator is applied to a component in one of the following ways:
Nest a validator tag inside the component's tag and reference the custom validator from
the validator tag.
Nest the validator's custom tag (if there is one) inside the component's tag.
To use a custom component, you add the custom tag associated with the component to the
page.
As explained in
"Setting Up a Page" on page 322
, you must ensure that the TLD that defines any
custom tags is packaged in the application if you intend to use the tags in your pages. TLD files
are stored in the WEB-INF/ directory or subdirectory of the WAR file or in the META-INF/
directory or subdirectory of a tag library packaged in a JAR file.
You also need to include a taglib declaration in the page so that the page has access to the tags.
All custom objects for the Duke's Bookstore application are defined in bookstore.tld. Here is
the taglib declaration that you would include on your page so that you can use the tags from
this TLD:
<%@ taglib uri=
"/WEB-INF/bookstore.tld" prefix="bookstore" %>
When including the custom tag in the page, you can consult the TLD to determine which
attributes the tag supports and how they are used.
Using Custom Objects
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
373