JBoss.orgCommunity Documentation

Chapter 11. Tables and grids

11.1. <a4j:repeat>
11.1.1. Basic usage
11.1.2. Limited views and partial updates
11.1.3. Reference data
11.2. <rich:column>
11.2.1. Basic usage
11.2.2. Spanning columns
11.2.3. Spanning rows
11.2.4. Reference data
11.3. <rich:columnGroup>
11.3.1. Complex headers
11.3.2. Reference data
11.4. <rich:dataGrid>
11.4.1. Basic usage
11.4.2. Customizing the grid
11.4.3. Patial updates
11.4.4. Reference data
11.5. <rich:dataTable>
11.5.1. Basic usage
11.5.2. Customizing the table
11.5.3. Partial updates
11.5.4. Reference data
11.5.5. <rich:dataTable> style classes and skin parameters
11.6. <rich:extendedDataTable>
11.6.1. Basic usage
11.6.2. Table appearance
11.6.3. Extended features
11.6.4. Reference data
11.7. <rich:list>
11.7.1. Basic usage
11.7.2. Type of list
11.7.3. Bullet and numeration appearance
11.7.4. Customizing the list
11.7.5. Reference data
11.8. Table filtering
11.8.1. Basic filtering
11.8.2. External filtering
11.9. Table sorting
11.9.1. Basic sorting
11.9.2. External 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 <a4j:repeat> component is used to iterate changes through a repeated collection of components. It allows specific rows of items to be updated without sending Ajax requests for the entire collection. The <a4j:repeat> component forms the basis for many of the tabular components detailed in Chapter 11, Tables and grids.

The <a4j:repeat> component uses other attributes common to iteration components, such as the first attribute for specifying the first item for iteration, and the rows attribute for specifying the number of rows of items to display.

Specific cells, rows, and columns can be updated without sending Ajax requests for the entire collection. Components that cause the change can specify which part of the table to update through the render attribute. The render attribute specifies which part of a table to update:

Alternatively, keywords can be used with the render attribute:

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

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 11.5, “Complex headers using column groups” and the resulting Figure 11.4, “Complex headers using column groups” demonstrate how complex headers can be achieved.

Example 11.5. Complex headers using column groups


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.

The <rich:dataGrid> component is similar in function to the JavaServer Faces <h:panelGrid> component. However, the <rich:dataGrid> component additionally allows iteration through the data model rather than just aligning child components in a grid layout.

Figure 11.5. The <rich:dataGrid> component


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> and <rich:columnGroup> components to list the contents of a 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.


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

Table 11.1. Style classes (selectors) with corresponding skin parameters

Class (selector) nameSkin ParametersCSS properties mapped 
.rich-table

This class defines the styles for a table.

tableBackgroundColorbackground-color 
.rich-table-cell

This class defines the styles for a table cell.

generalSizeFontfont-size 
generalTextColorcolor 
generalFamilyFontfont-family 
.rich-table-header

This class defines the styles for a table header row.

headerBackgroundColorbackground-color 
.rich-table-header-continue

This class defines the styles for all header lines after the first.

headerBackgroundColorbackground-color 
.rich-table-headercell

This class defines the styles for a header cell.

tableBorderWidth, tableBorderColorborder-right, border-bottom 
headerTextColorcolor 
headerWeightFontfont-weight 
generalSizeFontfont-size 
generalFamilyFontfont-family 
.rich-table-subheader

This class defines the styles for a column header.

additionalBackgroundColorbackground-color 
.rich-table-thead

This class defines the styles for the separator between the header and the rest of the table.

tableBorderWidth, tableBorderColorborder-bottom 
.rich-table-subheadercell

This class defines the styles for a column header cell.

tableBorderWidth, tableBorderColorborder-right 
generalTextColorcolor 
generalSizeFontfont-size 
generalFamilyFontfont-family 
.rich-table-footer

This class defines the styles for a footer row.

tableFooterBackgroundColorbackground-color 
.rich-table-footer-continue

This class defines the styles for all footer lines after the first.

tableFooterBackgroundColorbackground-color 
.rich-table-footercell

This class defines styles for a footer cell.

tableBorderWidth, tableBorderColorborder-right, border-bottom 
generalTextColorcolor 
headerWeightFontfont-weight 
generalSizeFontfont-size 
generalFamilyFontfont-family 
.rich-table-subfooter

This class defines the styles for a column footer.

tableSubfooterBackgroundColorbackground-color 
.rich-table-subfootercell

This class defines the styles for a column footer cell.

tableBorderWidth, tableBorderColorborder-right, border-bottom 
generalTextColorcolor 
generalSizeFontfont-size 
generalFamilyFontfont-family 

Style classes (selectors) without skin parameters

.rich-table-caption

This class defines styles for a "caption" facet element.

.rich-table-row

This class defines styles for a table row.

.rich-table-firstrow

This class defines styles for a table's first row.

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:

frozenColumnsonselectionchangeselectionMode
heightselectedClasstableState
noDataLabelselection 

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

Example 11.8. <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 11.8. <rich:extendedDataTable> example



Example 11.8, “<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.

The <rich:list> component renders a list of items. The list can be an numerically ordered list, an unordered bullet-point list, or a data definition list. The component uses a data model for managing the list items, which can be updated dynamically.

Tables entries can be filtered by the user through either the basic method built in to the <rich:column> component, or by defining external filters. Refer to Section 11.2, “<rich:column>” for details on using the <rich:column> component in tables.

The built-in filtering abilities of the <rich:column> component allow the user to enter text as a filtering value. The table displays only those entries that begin with the filter value.

Set the filterValue attribute to point to the value used to filter the column. This can be either an initial filtering value on the page, or a value binding on the server. The filterValue value is then used with the JavaScript startsWith() method to filter the column entries based on the data specified with the filterBy attribute. Expressions in the filterBy attribute must refer to the variable declared in the table's var attribute, which is used to fill the contents of the table.

The filter is processed and the table is rendered when the onblur event occurs for the column. This can be changed by defining a different event with the filterEvent attribute. For example, to implement live updating such that the filter refreshes after every keystroke, set filterEvent="onkeyup".


If you require more advanced filtering using custom functions or expressions, use the external filtering properties of the <rich:column> component.

Use the filterExpression attribute to define an expression that can be evaluated as a boolean value. The expression checks if each table entry satisfies the filtering condition when the table is rendered.

Use the filterMethod attribute to define a method binding. The method needs to accept an object as a parameter and return a boolean value. Similar to the filterExpression attribute, the table is rendered only with those entries that satisfy the filtering condition. By defining a custom filtering method, you can implement complex business logic to filter a table.

Example 11.12. External filtering


<rich:dataTable value="#{capitalsBean.capitals}" var="cap" id="table">
   <f:facet name="header">
      <rich:column>
         <h:outputText value="State Name">
      </rich:column>
      <rich:column>
         <h:outputText value="State Time Zone">
      </rich:column>
   </f:facet>
   <rich:column filterMethod="#{filteringBean.filterStates}">
        <f:facet name="header">
            <h:inputText value="#{filteringBean.filterValue}" id="input">
                <a4j:ajax event="onkeyup" render="table"
                              ignoreDupResponses="true" requestDelay="700"/>
            </h:inputText>
        </f:facet>
      <h:outputText value="#{cap.state}"/>
   </rich:column> 
   <rich:column filterExpression=
      "#{fn:containsIgnoreCase(cap.timeZone, filteringBean.filterZone)}">
        <f:facet name="header">
            <h:selectOneMenu value="#{filteringBean.filterZone}">
                <f:selectItems value="#{filteringBean.filterZones}" />
                <a4j:ajax event="onchange" render="table" />
            </h:selectOneMenu>
        </f:facet>
      <h:outputText value="#{cap.timeZone}"/> 
   </rich:column>
</rich:dataTable>

The example uses a filter expression on the first column and a filter method on the second column.


Tables entries can be sorted by the user through either the basic method built in to the <rich:column> component, or by defining external sorting algorithms. Refer to Section 11.2, “<rich:column>” for details on using the <rich:column> component in tables.

Sorting non-English tables

To sort a table whose contents are not in English, add the org.richfaces.datatableUsesViewLocale context parameter to the project's web.xml settings file. Set the value of the context parameter to true.

The built-in sorting functionality of the <rich:column> component allows a user to click the header of a column to sort it in ascending or descending order.

Set the sortBy attribute to indicate which value to use when sorting the column. Expressions in the sortBy attribute must refer to the variable declared in the table's var attribute, which is used to fill the contents of the table.


Use the sortOrder attribute to set how the table's contents are sorted when it is first loaded. By default, the value of the sortOrder attribute is unsorted, so that table entries appear in the order the are contained in the data model. Use sortOrder="ascending" to sort the entries in ascending alphabetical or numerical order. Use sortOrder="descending" to sort the entries in descending alphabetical or numerical order. The sortOrder attribute can also be used to externally set the sort order of a table when using the external sorting method; refer to Section 11.9.2, “External sorting” for details.

Use the sortMode attribute to determine how multiple columns are sorted. By default, the value of the sortMode attribute is single, so tables are only sorted by a single column. Each time the header of a column is clicked the entire table is re-sorted according to that column. Set sortMode="multiple" to allow tables to be sorted by a primary column, then by a secondary column, and so on.

If you require more advanced sorting using custom functions or expressions, use the external sorting properties of the <rich:column> component.

Deactivate the built-in sorting by setting selfSorted="false" for the <rich:column> component. You can then bind the sortOrder attribute to bean properties and manage the sorting order externally.

Example 11.14. External sorting


<rich:dataTable value="#{dataTableScrollerBean.allCars}"
                var="category" rows="20" id="table" reRender="ds2"
                sortPriority="#{sortingBean.prioritList}">
   <rich:column id="make" sortBy="#{category.make}"
                sortOrder="#{sortingBean.makeDirection}" selfSorted="false">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Make" />
      </f:facet>
      <h:outputText value="#{category.make}" />
   </rich:column>
   <rich:column id="model" sortBy="#{category.model}"
                sortOrder="#{sortingBean.modelDirection}" selfSorted="false">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Model" />
      </f:facet>
      <h:outputText value="#{category.model}" />
   </rich:column>
   <rich:column id="price" sortBy="#{category.price}"
                sortOrder="#{sortingBean.priceDirection}" selfSorted="false">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Price" />
      </f:facet>
      <h:outputText value="#{category.price}" />
   </rich:column>
   <rich:column id="mileage" sortBy="#{category.mileage}"
                sortOrder="#{sortingBean.mileageDirection}" selfSorted="false">
      <f:facet name="header">
         <h:outputText styleClass="headerText" value="Mileage" />
      </f:facet>
      <h:outputText value="#{category.mileage}" />
   </rich:column>
</rich:dataTable>

The example uses an external control to manage the table's sorting.


When using the sortMode="multiple" configuration, set the priority by which columns are sorted with the sortPriorities attribute.

Use the sortExpression attribute to define a bean property to use for sorting the column. The expression checks each table entry against the sorting expression during rendering.