A while ago I decided to create an ADF page based on a dynamic table, and I found that, although there are quite some articles about the subject online, I still faced some challenges while implementing such a solution in ADF 12c. These challenges, however, can be solved easily when you know some basic principles, and I would like to share those.
First, let me define what I mean with dynamic table in this post. It is an ADF table, specified in the JSF file with the af:table tag, with an unknown number of columns and rows. Moreover, the number of columns is still unknown when you run the page, as opposed to solutions where a table is created at runtime, based on a query.
We can add to that another feature: this table is not based on a database table nor a query, but will be built up at runtime based an a set of data that we will retrieve at the user’s request.
Use case: importing data with a time dimension
Why would we need such a table? Let me give a practical example: we want to let the user import a file, which is a CSV file export of a spreadsheet, in which the columns represent the time dimension. For instance, each column represents a day. Since we don’t know on forehand for how many days we will import data, we cannot build a view or table which has a column for each day.
On the other hand, when we will store the data in a database table, this table will have a date column (or attribute) in which the date column value from the CSV file will be stored.
So the database data model is very different from the data model we can read from the CSV file.
And the reason we want to show this data in the ADF table is simple: we want to show to the user that the CSV file has been read by the program successfully and that the columns as shown in our ADF page correspond to the columns in the spreadsheet the data has come from.
Demo: creating rows and columns at the user’s request
The demo application that I provide with this post, is meant to illustrate how a dynamic ADF table can be created, and how data can be read from and written to that table. As I want to keep the demo application as simple as possible, I concentrate on the ADF table, and will leave out the functionality of the storing data in the database or reading it from a file.
What I do include in the demo, is that the table is editable, so we can see that it is working properly.
For this purpose, the demo contains three buttons: two for adding columns and rows, and one to dump the contents of the entire table to the console.
On starting the application up, the following screen appears: a table with zero columns and zero rows. Read the complete article here.
For regular information become a member in the WebLogic Partner Community please visit: http://www.oracle.com/partners/goto/wls-emea ( OPN account required). If you need support with your account please contact the Oracle Partner Business Center.