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 embedding page as well as exporting the data from the table to an Excel file. Pretty impressive. And many of the visual configurations can be stored using Change Persistence across requests and even across sessions.
One specific requirement on a recent ADF 11g project led me to investigating if and how the ordering of columns in a rich table can be manipulated programmatically (rather than having the user to it). Earlier articles on this blog discussed similar challenges: intercepting changes in the column order applied by a user (http://technology.amis.nl/2012/02/intercepting-user-customization-such-as-column-reordering-in-tables-in-adf-11g-change-persistence/) and programmatically setting the sort order for columns in a Rich Table (http://technology.amis.nl/2012/03/adf-11g-programmatically-configuring-sort-for-rich-table/). As in these cases, the solution turns out to be fairly simple.
Changes applied at run time to the UI components in an ADF Faces page based on manipulations recorded through Change Persistence are applied through the ChangeManager class. In the same way ADF uses the ChangeManager to apply these changes read from MDS, we can also leverage the ChangeManager to apply our own changes. The article on intercepting column repositioning provided insight in the nature of the change: the repositioning of a column is recorded and applied as a change of type AttributeComponentChange. This class has a constructor that takes two arguments: the name of the attribute – displayIndex in this case – and the value of the attribute – an int specifying the new position of the column. The change can be applied to the RichColumn component using the addComponentChange method on the ChangeManager. This method takes three arguments: the current facesContext, the RichColumn on which to apply the change and the AttributeComponentChange object.
With this information, we can create the following code that complete reverses the initial ordering of columns in a table:
The method reorganizeColumnsInTable is invoked from a button in the page:
and results in the table being refreshed like this:
- ADF 11g: programmatically configuring sort for rich table
- ADF 11g Rich Client Components – programmatically adding a ShowPopupBehavior
- ADF Faces – Client Side Column Hide and Seek – Expanding/Collapsing Columns in Table
- ADF Faces – Server Side (partial page rendering) Column Hide and Seek – Expanding/Collapsing Columns in Table
- Changing the order of columns in a JSF Table Component -in the client, at run-time, by the end user
- My Report from the ODTUG Kscope13
- ADF: (Automatic) Partial Page Rendering across Taskflows
- ADF client-side architecture – Select All
- ADF 184.108.40.206 : The return of the paging table (… and more ….)
- ADF DVT Speed Date: Interactive Bubble Graph
- Dear Java/JEE developer – why should you care about ADF?
- Book Review : Oracle ADF Real World Developer’s Guide
- The ultimate ADF event of 2012: The AMIS Master Class Advanced ADF – Christmas Special (Friday 21st of December)
- Maak bij AMIS als eerste kennis met Oracle ADF Mobile!
- ADF Mobile : Your First Navigation and Device Interaction