On Java Development

All things related to Java development, from the perspective of a caveman.

RichFaces Data Tables

without comments

Introduction

This post presents information about the coding needed to present data using a RichFaces Data Table.

 

Defining a Data Table

Shown below is the XHTML code used to define a RichFaces data table. The definition of the table is enclosed between <rich:dataTable… and </rich:dataTable> which defines the following:

  • The data table’s id. Although one is automatically assigned if omitted, it’s best to assign one so that you can reference it when needed. Otherwise, its name cannot be determined.
    id=”id-PrescriptionsTable”
  • The collection of data to be displayed. This is typically an ArrayList object consisting of a collection of Entity objects each of which represent the record/data to display. The classes contained do not need to be actual Entity objects. When preferred they can be designed so that they are tailored for the display requirements so that only the fields that are needed with any associated helper methods are present.
    value=”#{page02ManagedBean.listOfINGRXP}”
  • The variable name given to each of the POJO’s contained in the collection (listOfINGRXP).
    var=”record”
  • The number of rows to be displayed per page.
    rows=”15″
  • The index to the first row.
    first=”0″
  • The variable name given to the iterator value.
    iterationStatusVar=”it”
  • The column classes assigned to column data . These are Cascading Style Sheet (CSS) classes that define the alignments of the data in each column, NOT the entry for the column’s title.
    columnClasses=”alignLeft, alignCenter, …

Shown here are the CSS classes used for data alignment.

Following the <rich:dataTable… definition are the column definitions. A few representative entries are shown.

The first column definition is responsible for the line numbers. Displaying them helps to inform the user of where they are when paging through large sets of data. It takes its value from the iterator defined for the table. (iterationStatusVar=”it”) The headerClass=”alignCenter” definition is used to control the alignment of the column’s header.

The second column definition (lines 17-32) defines a commandLink. When selected the application navigates to a screen showing the associated detail of the record. The icon depicting reading glasses is also displayed for this column. Below are a few items highlighting some of its aspects.

  • The column’s identifier. The identifier is created by concatenating “id-viewLink” with the iterator’s current value.
  • The assignTo=”#{page01ManagedBean.currentRecordIndex}”.
    This amounts to being the equivalent to a subfile’s RRN.
  • The entry <f:setPropertyActionListener… is responsible for setting the record selected from the list which is represented by the “record” variable. The method called is shown below.

Following the column definitions, a JSF Facet is used to contain a RichFaces Data Scroller that is used to allow the user to navigate each page of data. The id shown refers to the same id given to the table. This is required for the data scroller to work properly. Also, the name for the facet must be “footer”.

 
A full set of definitions presented above presents the data table shown below. The “Prescription Number” column defined above is shown. Note the alignment of the column header and the data.

RichFacesDataTable

Written by admin

November 21st, 2014 at 9:09 am

Leave a Reply

You must be logged in to post a comment.