JBoss.orgCommunity Documentation

Chapter 9. Tables and grids

9.1. <rich:column>
9.2. <rich:columnGroup>
9.3. <rich:columns>
9.4. <rich:dataDefinitionList>
9.5. <rich:dataFilterSlider>
9.6. <rich:dataGrid>
9.7. <rich:dataList>
9.8. <rich:dataOrderedList>
9.9. <rich:dataTable>
9.10. <rich:extendedDataTable>
9.11. Table filtering
9.12. Table sorting

Documentation in development

Some concepts covered in this chapter may refer to the previous version of Richfaces , version 3.3.3. This chapter is scheduled for review to ensure all information is up to date.

This chapter covers all components related to the display of tables and grids.

The <rich:column> component facilitates columns in a table or other UIData component. It supports merging columns and rows, sorting, filtering, and customized skinning.

In general usage, the <rich:column> component is used in the same was as the JavaServer Faces (JSF) <h:column> component. It requires no extra attributes for basic usage, as shown in Example 9.1, “Basic column example”.


Columns can be merged by using the colspan attribute to specify how many normal columns to span. The colspan attribute is used in conjunction with the breakBefore attribute on the next column to determine how the merged columns are laid out. Example 9.2, “Column spanning example”.


Similarly, the rowspan attribute can be used to merge and span rows. Again the breakBefore attribute needs to be used on related <rich:column> components to define the layout. Example 9.3, “Row spanning example” and the resulting Figure 9.4, “Complex headers using column groups” show the first column of the table spanning three rows.


For details on filtering and sorting columns, refer to Section 9.11, “Table filtering” and Section 9.12, “Table sorting”.

The <rich:columnGroup> component combines multiple columns in a single row to organize complex parts of a table. The resulting effect is similar to using the breakBefore attribute of the <rich:column> component, but is clearer and easier to follow in the source code.

The <rich:columnGroup> can also be used to create complex headers in a table. Example 9.4, “Complex headers using column groups” and the resulting Figure 9.4, “Complex headers using column groups” demonstrate how complex headers can be achieved.


The <rich:columns> component allows for dynamic sets of columns for tables. Columns and rows can be merged, and the look and feel can be highly customized. The component gets a list from a data model and creates a corresponding set of columns in a <rich:dataTable> component. The <rich:columns> component also supports header and footer facets.

Basic usage of the <rich:columns> component requires the value attribute, which points to the data model; the var attribute, which holds the current variable for the collection of data; and the index attribute, which holds the current counter. The id attribute is used for when the individuals rows require identifiers for Ajax events.


The output can be customized to display specific columns and rows. The columns attribute specifies the number of columns. The rowspan attribute specifies the number of rows to display; if the attribute is set to 0, all remaining rows in the table are displayed. The begin and end attributes are used to specify the first and last zero-based iteration items to display in the table. Columns can be adjusted using the colspan, rowspan, and breakBefore attributes the same as with the <rich:column> component.

The <rich:columns> component can be used alongside <rich:column> components.


For details on filtering and sorting columns, refer to Section 9.11, “Table filtering” and Section 9.12, “Table sorting”.

The <rich:dataDefinitionList> component renders a list of items with definitions. The component uses a data model for managing the list items, which can be updated dynamically.

The var attribute names a variable for iterating through the items in the data model. The items to iterate through are determined with the value attribute by using EL (Expression Lanugage). The first attribute specifies which item in the data model to start from, and the rows attribute specifies the number of items to list. The title attribute is used for a floating tool-tip. Example 9.7, “<rich:dataDefinitionList> example” shows a simple example using the <rich:dataDefinitionList> component.


The <rich:dataFilterSlider> components is a slider control that can be used for filtering data in a table. The range and increment of the slider control are defined using the startRange, endRange, and increment attributes.

The slider is bound to a UIData component specified with the for attribute. The forValRef attribute refers to the value attribute used by the target component, and the filterBy attribute specifies which object member to filter according to the slider.

The handleValue attribute keeps the current handle position on the slider control; filtering is based on this value. The storeResults attribute allows the <rich:dataFilterSlider> component to keep the target UIData component in session.

The event defined with the submitOnSlide attribute is triggered when the handle value on the slider is changed.


The <rich:dataGrid> component is used to arrange data objects in a grid. Values in the grid can be updated dynamically from the data model, and Ajax updates can be limited to specific rows. The component supports header, footer, and caption facets.

Figure 9.7. The <rich:dataGrid> component


The <rich:dataGrid> component requires the value attribute, which points to the data model, and the var attribute, which holds the current variable for the collection of data. The number of columns for the grid is specifed with the columns attribute, and the number of elements to layout among the columns is determined with the elements attribute. The first attribute references the zero-based element in the data model from which the grid starts.


As the component is based on the <a4j:repeat> component, it can be partially updated with Ajax. The ajaxKeys attribute allows row keys to be defined, which are updated after an Ajax request.


The <rich:dataList> component renders an unordered list of items. The component uses a data model for managing the list items, which can be updated dynamically.

The type attribute refers to the appearance of the bullet points. The values of the attribute correspond to the type parameter for the <ul> HTML element:

The var attribute names a variable for iterating through the items in the data model. The items to iterate through are determined with the value attribute by using EL (Expression Lanugage). The first attribute specifies which item in the data model to start from, and the rows attribute specifies the number of items to list. The title attribute is used for a floating tool-tip. Example 9.7, “<rich:dataDefinitionList> example” shows a simple example using the <rich:dataDefinitionList> component.


The <rich:dataOrderedList> component renders an ordered list of items from a data model. Specific rows can be updated dynamically without updating the entire list.

The type attribute defines the appearance of the numerating list markers for the list. The possible values for the type attribute are as follows:

The first attribute specifies which item in the data model to start from, and the rows attribute specifies the number of items to list. The title attribute defines a pop-up title. To only update a sub-set of the rows in the list, use the ajaxKeys attribute, which points to an object that contains the specified rows.


The <rich:dataTable> component is used to render a table, including the table's header and footer. It works in conjunction with the <rich:column>, <rich:columnGroup>, and <rich:columns> components to list the contents of a data model.

The value attribute points to the data model, and the var attribute specifies a variable to use when iterating through the data model. The first attribute specifies which item in the data model to start from, and the rows attribute specifies the number of items to list. The header, footer, and caption facets can be used to display text, and to customize the appearance of the table through skinning. demonstrates a simple table implementation.


The <rich:dataTable> component is based on the <a4j:repeat> component, and as such it can be partially updated using Ajax. The ajaxKeys attribute defines the rows to be updated during an Ajax request.

For details on filtering and sorting data tables, refer to Section 9.11, “Table filtering” and Section 9.12, “Table sorting”.

The <rich:extendedDataTable> component builds on the functionality of the <rich:dataTable> component, adding features such as data scrolling, row and column selection, and rearranging of columns.

The <rich:extendedDataTable> component includes the following attributes not included in the <rich:dataTable> component:

activeClassheightselection
activeRowKeynoDataLabelselectionMode
enableContextMenuonselectionchangetableState
groupingColumnselectedClass 

The <rich:extendedDataTable> component does not include the following attributes available with the <rich:dataTable> component:

Basic use of the <rich:extendedDataTable> component requires the value and var attributes, the same as with the <rich:dataTable> component. Refer to Section 9.9, “<rich:dataTable>” for details.

The height attribute is mandatory, and defines the height of the table on the page. This is set to 500px by default. The width of the table can be set by using the width attribute. As with the <rich:dataTable> component, the look of the <rich:extendedDataTable> component can be customized and skinned using the header, footer, and caption facets.

Example 9.14. <rich:extendedDataTable> example


<rich:extendedDataTable id="edt" value="#{extendedDT.dataModel}" var="edt" width="500px" height="500px" selectedClass="dataTableSelectedRow" sortMode="single" selectionMode="multi" selection="#{extendedDT.selection}" rowKeyVar="rkvar" tableState="#{extendedDT.tableState}">
    <rich:column id="id" headerClass="dataTableHeader" width="50" label="Id" sortable="true" sortBy="#{edt.id}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon">
        <f:facet name="header">
            <h:outputText value="Id" />
        </f:facet>
        <h:outputText value="#{edt.id}" />
    </rich:column>
    <rich:column id="name" width="300" headerClass="dataTableHeader" label="Name" sortable="true" sortBy="#{edt.name}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon" filterBy="#{edt.name}" filterEvent="onkeyup" visible="false"> 
        <f:facet name="header"> 
            <h:outputText value="Name" />
        </f:facet>
        <h:outputText value="#{edt.name}" />
    </rich:column>
    <rich:column id="date" width="100" headerClass="dataTableHeader" label="Date" sortable="true" comparator="#{extendedDT.dateComparator}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon">
        <f:facet name="header">
            <h:outputText value="Date" />
        </f:facet>
        <h:outputText value="#{edt.date}"><f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss" />
        </h:outputText>
    </rich:column>
    <rich:column id="group" width="50" headerClass="dataTableHeader" label="Group" sortable="true" sortBy="#{edt.group}" sortIconAscending="dataTableAscIcon" sortIconDescending="dataTableDescIcon">
        <f:facet name="header">
            <h:outputText value="Group" />
        </f:facet>
        <h:outputText value="#{edt.group}" />
    </rich:column>
</rich:extendedDataTable>

Figure 9.12. <rich:extendedDataTable> example



Example 9.14, “<rich:extendedDataTable> example” shows an example extended data table. The implementation features a scrolling data table, selection of one or more rows, sorting by columns, grouping by column, and a filter on the Name column.

Row selection is determined by the selectionMode attribute. Setting the attribute to none allows for no row selection capability. Setting the selectionMode attribute to single allows the user to select a single row at a time using the mouse. With the selectionMode attribute set to multi, the user can select multiple rows by holding down the Shift or Ctrl keys while clicking. The selection attribute points to the object that tracks which rows are selected. Figure 9.13, “Selecting multiple rows” shows the table from the example with multiple rows selected.

Figure 9.13. Selecting multiple rows


The example uses the filter facet of the <rich:column> component to display the text field. A user can type their criteria into the text field to customize the filter of the column below. For full details on filtering tables, refer to Section 9.11, “Table filtering”.

When hovering the mouse over a column header, a menu button appears to the right-hand side, as shown in Figure 9.14, “Column menu”. This menu allows the user to sort the contents of the column, group the table by the column, or hide and show columns.

Figure 9.14. Column menu


Each column can allow sorting by setting the <rich:column> component's sortable attribute to true. The value of the data model to sort by is specified with the sortBy attribute. In addition to using the menu for sorting, columns can be quickly sorted either ascending or descending by clicking on the directional icon next to the column title. The directional icons are defined in each <rich:column> component with the sortIconAscending and sortIconDescending attributes, for ascending and descending icons respectively. For full details on sorting tables, refer to Section 9.12, “Table sorting”.

Grouping the table's entries by a column will organize the table into collapsible sections, as shown in Figure 9.15, “Grouping table entries by column”.

Figure 9.15. Grouping table entries by column


The checkboxes in the column menu under the Columns sub-menu will hide or show the respective columns, as shown in Figure 9.16, “Hiding columns”.

Figure 9.16. Hiding columns


Columns in a <rich:extendedDataTable> component can be rearranged by the user by dragging each column to a different position. The label attribute for the <rich:column> component is displayed during dragging, as shown in

Figure 9.17. Dragging columns


Once the contents of the table have been rearranged and customized by the user, the tableState attribute can be used to preserve the customization so it can be restored later. The tableState attribute points to a backing-bean property which can in turn be saved to a database separate from standard JSF state-saving mechanisms.

Under development.

Under development.