Java Reference
In-Depth Information
bean code. The next sections of the tutorial describe the use of the built-in Ajax resource
library.
In addition, because the JavaServer Faces technology component model can be extended,
custom components can be created with Ajax functionality.
An Ajax version of the guessnumber application, ajaxguessnumber , is available
in the example repository. See “ The ajaxguessnumber Example Application on page
81 for more information.
The Ajax specific f:ajax tag and its attributes are explained in the next sections.
Using Ajax with Facelets
As mentioned in the previous section, JavaServer Faces technology supports Ajax by us-
ing a built-in JavaScript resource library that is provided as part of the JavaServer Faces
core libraries. This built-in Ajax resource can be used in JavaServer Faces web applica-
tions in one of the following ways:
• By using the f:ajax tag along with another standard component in a Facelets
application. This method adds Ajax functionality to any UI component without ad-
ditional coding and configuration.
• By using the JavaScript API method jsf.ajax.request() directly within the
Facelets application. This method provides direct access to Ajax methods, and al-
lows customized control of component behavior.
Using the f:ajax Tag
The f:ajax tag is a JavaServer Faces core tag that provides Ajax functionality to any
regular UI component when used in conjunction with that component. In the following
example, Ajax behavior is added to an input component by including the f:ajax core
tag:
<h:inputText value="#{bean.message}">
<f:ajax />
</h:inputText>
In this example, although Ajax is enabled, the other attributes of the f:ajax tag are not
defined. If an event is not defined, the default action for the component is performed. For
the inputText component, when no event attribute is specified, the default event is
valueChange . Table 4-1 lists the attributes of the f:ajax tag and their default ac-
tions.
Search WWH ::




Custom Search