background image

The UIData Component

<< The dataTable Tag | The first Attribute >>
<< The dataTable Tag | The first Attribute >>

The UIData Component

The column tags represent columns of data in a UIData component. While the UIData
component is iterating over the rows of data, it processes the UIColumn component associated
with each column tag for each row in the table.
The UIData component shown in the preceding code example iterates through the list of books
(cart.items) in the shopping cart and displays their titles, authors, and prices. Each time
UIData
iterates through the list of books, it renders one cell in each column.
The dataTable and column tags use facets to represent parts of the table that are not repeated or
updated. These include headers, footers, and captions.
In the preceding example, column tags include facet tags for representing column headers or
footers. The column tag allows you to control the styles of these headers and footers by
supporting the headerClass and footerClass attributes. These attributes accept
space-separated lists of CSS style classes, which will be applied to the header and footer cells of
the corresponding column in the rendered table.
Facets can have only one child, and so a panelGroup tag is needed if you want to group more
than one component within a facet. Because the facet tag representing the footer includes
more than one tag, the panelGroup is needed to group those tags. Finally, this dataTable tag
includes a facet tag with its name attribute set to caption, causing a table caption to be
rendered below the table.
This table is a classic use case for a UIData component because the number of books might not
be known to the application developer or the page author at the time the application is
developed. The UIData component can dynamically adjust the number of rows of the table to
accommodate the underlying data.
The value attribute of a dataTable tag references the data to be included in the table. This data
can take the form of
A list of beans
An array of beans
A single bean
A javax.faces.model.DataModel
A java.sql.ResultSet
A javax.servlet.jsp.jstl.sql.ResultSet
A javax.sql.RowSet
All data sources for UIData components have a DataModel wrapper. Unless you explicitly
construct a DataModel wrapper, the JavaServer Faces implementation will create one around
data of any of the other acceptable types. See
"Writing Bean Properties" on page 379
for more
information on how to write properties for use with a UIData component.
The var attribute specifies a name that is used by the components within the dataTable tag as
an alias to the data referenced in the value attribute of dataTable.
Adding UI Components to a Page Using the HTML Component Tags
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
339