As you probably know, the “Table” component allows you to use an out of the box filtering.
A while ago, I’ve been asked to execute a table filtering programmatically – that is, use a java code to automatically populate the filter.
In my current example I’m using a button to perform a filtering action. Of curse you can use the code in many other ways,
Well, here are the steps:
First, add a binding to the table with getter & setter:
Second, drag a new button and create an “ActionListener” with the following code (I’ve copied the full class):
package adf; import java.util.HashMap; import java.util.Map; import javax.faces.event.ActionEvent; import oracle.adf.view.rich.component.rich.data.RichTable; import oracle.adf.view.rich.context.AdfFacesContext; import oracle.adf.view.rich.event.QueryEvent; import oracle.adf.view.rich.model.FilterableQueryDescriptor; public class action { private RichTable tblBind; public action() { } public void setFilter(ActionEvent actionEvent) { RichTable tbl = this.getTblBind(); FilterableQueryDescriptor filterQD = (FilterableQueryDescriptor)tbl.getFilterModel(); Map filterCriteria = filterQD.getFilterCriteria(); Map<String, String> data = new HashMap<String, String>(); data.put("Id","888 OR 999"); filterCriteria.putAll(data); getTblBind().queueEvent(new QueryEvent(getTblBind(), filterQD)); AdfFacesContext.getCurrentInstance().addPartialTarget(this.getTblBind()); } public void setTblBind(RichTable tblBind) { this.tblBind = tblBind; } public RichTable getTblBind() { return tblBind; } }
And the result, when pressing the “Filter” button:
Note the following:
- The code refers to the table binding we’ve created earlier
- The Mapping points to the table’s column name, in my case: “Id”
- For the example, I used filter with 1 “OR” operator, You can use more then 1 and also other operators, like “AND”
That’s it.
Good Luck
FilterableQueryDescriptor.getFilterCriteria() method is deprecated in ADF 12c. You should use getFilterConjunctionCrtietrion() method instead and the methods of ConjunctionCriterion and AttributeCriterion classes, for example:
ConjunctionCriterion filterCriterion = queryDescriptor.getFilterConjunctionCriterion();
AttributeCriterion ac = (AttributeCriterion)filterCriterion.getCriterionMap().get(“Id”);
ac.setValue(“888 OR 999”);