Download
FAQ History |
![]() ![]() ![]() |
API
Search Feedback |
User Interface Component Model
JavaServer Faces UI components are configurable, reusable elements that compose the user interfaces of JavaServer Faces applications. A component can be simple, like a button, or compound, like a table, which can be composed of multiple components.
JavaServer Faces technology provides a rich, flexible component architecture that includes:
- A set of
UIComponent
classes for specifying the state and behavior of UI components- A rendering model that defines how to render the components in different ways.
- An event and listener model that defines how to handle component events
- A conversion model that defines how to plug in data converters onto a component
- A validation model that defines how to register validators onto a component
This section briefly describes each of these pieces of the component architecture.
The User-Interface Component Classes
JavaServer Faces technology provides a set of UI component classes, which specify all of the UI component functionality, such as holding component state, maintaining a reference to model objects, and driving event-handling and rendering for a set of standard components.
These classes are completely extensible, which means that component writers can extend the classes to create their own custom components. See Creating Custom UI Components for an example of a custom image map component.
All JavaServer Faces UI component classes extend from
UIComponentBase
, which defines the default state and behavior of aUIComponent
. The set of UI component classes included in this release of JavaServer Faces are:
UICommand
: Represents a control that fires actions when activated.UIForm
: Encapsulates a group of controls that submit data to the application. This component is analogous to the form tag in HTML.UIGraphic
: Displays an image.UIInput
: Takes data input from a user. This class is a subclass ofUIOutput
.UIOutput
: Displays data output on a page.UIPanel
: Displays a table.UIParameter
: Represents substitution parameters.UISelectItem
: Represents a single item in a set of items.UISelectItems
: Represents an entire set of items.UISelectBoolean
: Allows a user to set aboolean
value on a control by selecting or de-selecting it. This class is a subclass ofUIInput
.UISelectMany
: Allows a user to select multiple items from a group of items. This class is a subclass ofUIInput
.UISelectOne
: Allows a user to select one item out of a group of items.This class is a subclass ofUIInput
.Most page authors and application developers will not have to use these classes directly. They will instead include the components on a page by using the component's corresponding tag. Most of these component tags can be rendered in different ways. For example, a
UICommand
can be rendered as a button or a hyperlink.The next section explains how the rendering model works and how page authors choose how to render the components by selecting the appropriate tag.
The Component Rendering Model
The JavaServer Faces component architecture is designed such that the functionality of the components is defined by the component classes, whereas the component rendering can be defined by a separate renderer. This design has several benefits including:
- Component writers can define the behavior of a component once, but create multiple renderers, each of which defines a different way to render the component to the same client or to different clients.
- Page authors and application developers can change the appearance of a component on the page by selecting the tag that represents the appropriate component/renderer combination.
A render kit defines how component classes map to component tags appropriate for a particular client. The JavaServer Faces implementation includes a standard
RenderKit
for rendering to an HTML client.For every UI component that a
RenderKit
supports, theRenderKit
defines a set ofRenderer
objects.
EachRenderer
defines a different way to render the particular component to the output defined by theRenderKit
. For example, aUISelectOne
component has three different renderers. One of them renders the component as a set of radio buttons. Another renders the component as a combo box. The third one renders the component as a list box.Each JSP custom tag in the standard HTML RenderKit is composed of the component functionality, defined in the
UIComponent
class, and the rendering attributes, defined by theRenderer
. For example, the two tags in Table 20-1 both represent aUICommand
component, rendered in two different ways:
The command part of the tags corresponds to the
UICommand
class, specifying the functionality, which is to fire an action. The button and hyperlink parts of the tags each correspond to a separateRenderer
, which defines how the component is rendered.The JavaServer Faces reference implementation provides a custom tag library for rendering components in HTML. It supports all of the component tags listed in Table 20-2. To learn how to use the tags in an example, see Using the JavaServer Faces Tag Libraries.
Conversion Model
A JavaServer Faces application can optionally associate a component with server-side model object data. This model object is a JavaBeans component that encapsulates the data on a set of components. An application gets and sets the model object data for a component by calling the appropriate model object properties for that component.
When a component is bound to a model object, the application has two views of the component's data: the model view and the presentation view, which represents the data in a manner that can be viewed and modified by the user.
A JavaServer Faces application must ensure that the component's data can be converted between the model view and the presentation view. This conversion is usually performed automatically by the component's renderer.
In some situations, you might want to convert a component's data to a type not supported by the component's renderer. To facilitate this, JavaServer Faces technology includes a set of standard
Converter
implementations and also allows you to create your own customConverter
implementations. If you register theConverter
implementation on a component, theConverter
implementation converts the component's data between the two views. See Performing Data Conversions for more details on the converter model, how to use the standard converters, and how to create and use your own custom converter.Event and Listener Model
One goal of the JavaServer Faces specification is to leverage existing models and paradigms so that developers can quickly become familiar with using JavaServer Faces in their web applications. In this spirit, the JavaServer Faces event and listener model leverages the JavaBeans event model design, which is familiar to GUI developers and Web Application Developers.
Like the JavaBeans component architecture, JavaServer Faces technology defines
Listener
andEvent
classes that an application can use to handle events generated by UI components. AnEvent
object identifies the component that generated the event and stores information about the event. To be notified of an event, an application must provide an implementation of theListener
class and register it on the component that generates the event. When the user activates a component, such as clicking a button, an event is fired. This causes the JavaServer Faces implementation to invoke the listener method that processes the event.JavaServer Faces supports two kinds of events: value-changed events and action events.
A value-changed event occurs when the user changes a component value. An example is selecting a checkbox, which results in the component's value changing to true. The component types that generate these types of events are the
UIInput
,UISelectOne
,UISelectMany
, andUISelectBoolean
components. Value-changed events are only fired if no validation errors were detected.An action event occurs when the user clicks a button or a hyperlink. The
UICommand
component generates this event.For more information on handling these different kinds of events, see Handling Events.
Validation Model
JavaServer Faces technology supports a mechanism for validating a component's local data during the Process Validations phase, before model object data is updated.
Like the conversion model, the validation model defines a set of standard classes for performing common data validation checks. The
jsf-core
tag library also defines a set of tags that correspond to the standardValidator
implementations.Most of the tags have a set of attributes for configuring the validator's properties, such as the minimum and maximum allowable values for the component's data. The page author registers the validator on a component by nesting the validator's tag within the component's tag.
Also like the conversion model, the validation model allows you to create your own
Validator
implementation and corresponding tag to perform custom validation. See Performing Validation for more information on the standardValidator
implementations and how to create customValidator
implementation and validator tags.
Download
FAQ History |
![]() ![]() ![]() |
API
Search Feedback |
All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.