ADF 11g: programmatically configuring sort for rich table

3

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.

 

Share.

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PLSQL), Service Oriented Architecture, BPM, ADF, Java in various shapes and forms and many other things. Author of the Oracle Press book: Oracle SOA Suite 11g Handbook. Frequent presenter on conferences such as JavaOne, Oracle OpenWorld, ODTUG Kaleidoscope, Devoxx and OBUG. Presenter for Oracle University Celebrity specials.

3 Comments

  1. public void sort(ValueChangeEvent valueChangeEvent)
    {
    String sortItem = valueChangeEvent.getNewValue().toString();
    if (sortItem.equals(“list”))
    {
    sortByName(“ListName”);
    }
    else if (sortItem.equals(“priority”))
    {
    sortByName(“Priority”);
    }
    else if (sortItem.equals(“dueDate”))
    {
    sortByName(“DueDate”);
    }
    else if (sortItem.equals(“doneFlag”))
    {
    sortByName(“DoneFlag”);
    }
    System.err.println(sortItem);
    AdfFacesContext.getCurrentInstance().addPartialTarget(baseTree);
    todoMenu.hide();
    }

    public String sortByName(String sortBy)
    {
    List sortList = new ArrayList();
    SortCriterion cs2 = new SortCriterion(sortBy, true);
    sortList.add(cs2);
    baseTree.setSortCriteria(sortList);
    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.

Leave a Reply