Browse Category by af:table
View Post

ADF: af:table filter modifications using a custom Query Listener

In one of our last projects we had the requirement to allow the user to filter tables using the table filter feature. By default you can filter String fields starting with the word that the user provides, but our customer needed to find the rows that contained the criteria.

This is an easy task that can be accomplished by creating a custom Query Listener method.

As by default the filter works with “Starts with” condition you will see that filtering by “tra” will give no result although departments like Administration exists.
In this example we will use Departments table in HR schema.

When we drag and drop to create a table and we set it to be filterable, we can see that a query listener has been created by default.

As we need to modify the filter values we need to create ouor own query listener.
The idea of this method is to get every value, and if it is String we have to change the original value and concatenate ‘%’ before and after the value.
After that we need to call the default query listener that we can get from queryListener property in the table component.
If we end here, the  user would see the new filter with % symbol, so we are going to remove it and leave it as the user type it.

This is the helper method we use to call the default  query listener.

The last step is to set our new method as the table’s query listener.

If we run the application we can see that if we filter by “tra”, we can now see some records.

ADF: Display Map values in af:table

When we want to populate an af:table programatically we usually use a collection based on a java bean (e.g. List<MyObject>) but in this post of JDeveloper & ADF the developer required to populate the table with Map values.
First we need to create a Map in our bean and add the values that we are going to show in the table.

If we try to populate the table we can see tat we need to know the keys of the Map to get the values.

As you can see Value Columns displays the value in the Map for ‘Key 1’ key, but using this method we can not dynamically display all values.

To solve this issue we need to create an array in our bean where we will have all keys of the Map.

Now that we have created in our bean all that we need, we can start building the table structure.

On the table of the second image we need to make some changes. First, instead of using Map property, we have to use the key array we have just created as value property of the table.

And, as we have to access Map values, we have to add an af:iterator inside the table and add the columns we need inside this iterator. The value property of this iterator is the Map property in the bean.

This way, to retrieve keys we are going to use #{row} and to retrieve values asociated to a key we are going to use #{var[row]}.

Oce we have finished with the changes, if we run the application we can see that all the values of the Map are displayed in the table without the need of knowing the keys of the Map.