ADF 11g: programmatically configuring sort for rich table

Lucas Jellema 4

A recent requirement on one of our ADF 11g projects: we want to gather a number of settings a user has applied to the rich table in one of the pages. These settings include position, width and visibility of columns (supported by change persistence) and custom data filter, sort configuration and highlight condition. These latter settings are not part of change persistence out of the box. An additional requirement is that this collection of settings is to be saved under a label and to be made available to all users for selection when they view that same table.

I like these requirements. They are tangible, concrete and add fun(ctionality) to the application that directly pleases the end users. With ADF 11g, it is not an extremely difficult requirement – it seems.

One of the aspects mentioned here – sort setting – requires us not only to intercept or capture changes in sort settings – which sortListener on the columns of the table will do nicely – but also the programmatic application of sort settings when the table is rendered and a ‘user saved packet of table settings’ is selected.

In this article I take a very brief look at how to programmatical set the sorting condition on the rich table’s columns.

Visually this functionality can be illustrated like this:

The table is shown with data that is currently sorted by Job. When the user clicks the button Sort by Name, our programmatic ‘set the sort property on the table’ code is invoked and the data is re-rendered, sorted by Name:

The underlying code is quite simple.

I have created a class TableManager and based on that class a managed bean called tableManager. This class has a property RichTable table with setter and getter method.

The <af:table> is bound to the managed bean through an EL expression:

The TableManager class contains a method sortByName:

This method creates a new sort criterion, based on the name property (which is one of the properties in the Employee class that is used for the objects in hrmBean.employees). This criterion is added to an otherwise empty list that is set as SortCriteria on the RichTable. Next, the table is added as partial target to the ADFFacesContext, which means that when the request completes, the table component is refreshed in the browser.

Finally, the button has its action property (could have been the actionListener as well) set to refer to the sortByName method:

When the button is pressed, the tableManager bean is invoked, method sortByName is executed, the sortCriteria on the table are manipulated and the table gets refreshed. Job done.


4 thoughts on “ADF 11g: programmatically configuring sort for rich table

  1. public void sort(ValueChangeEvent valueChangeEvent)
    String sortItem = valueChangeEvent.getNewValue().toString();
    if (sortItem.equals(“list”))
    else if (sortItem.equals(“priority”))
    else if (sortItem.equals(“dueDate”))
    else if (sortItem.equals(“doneFlag”))

    public String sortByName(String sortBy)
    List sortList = new ArrayList();
    SortCriterion cs2 = new SortCriterion(sortBy, true);
    return null;
    it’s sort only tree parent node sorting how to child node sort in adf tree.

  2. how to RichTree in Child node sort. pls help me. my developing modul is calendar control. Calendar control in consists of Calendars, calendar events, todoLists, todos. my project in TodoList and todo is adf tree. how to sort tree child node (i need sort in todosVO sort /todoTitle, doneFlag, dueDate, priority /) help me

  3. Trying to clear the sort order using same technique but it doesn’t work as setting a null or empty list is ignored and getting the current sort criteria to clear it returns a unmodifiable list.

Comments are closed.

Next Post

ADF 11g: Programmatically repositioning columns in a Rich Table

Rich Tables are powerful beasts in ADF Faces. They can present tons of information in many different ways. They allow users an extensive range of manipulation – from reordering and hiding columns, changing column width to sorting and filtering the data presented in the table and detaching the table from its […]
%d bloggers like this: