Hello All
This tutorial is about a requirement of filtering af:table column through code,
to achieve this we can invoke FilterableQueryDescriptor (FilterableQueryDescriptor is an abstract subclass of QueryDescriptor. It adds support for filtering of data and is typically used by the table component to filter data from a query )
Suppose i have department table and i have to filter on department column-
Managed Bean Code-
Run your Application-
Cheers- Download Sample App
This tutorial is about a requirement of filtering af:table column through code,
to achieve this we can invoke FilterableQueryDescriptor (FilterableQueryDescriptor is an abstract subclass of QueryDescriptor. It adds support for filtering of data and is typically used by the table component to filter data from a query )
Suppose i have department table and i have to filter on department column-
- Create a Fusion Web Application and business components for Departments (HR Schema) table
- now drag table on page and bind it to bean
- Now drop a input text and button on page to enter Department Name
- bind input text to bean and create ActionListener on button to filter Department Table
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="filterPage.jspx" id="d1"> <af:messages id="m1"/> <af:form id="f1"> <af:inputText label="Department Name" id="it5" binding="#{pageFlowScope.FilterProgrammaticBean.deptNmBind}"/> <af:commandButton text="Filter" id="cb1" actionListener="#{pageFlowScope.FilterProgrammaticBean.filterTableAction}"/> <af:table value="#{bindings.DepartmentsView1.collectionModel}" var="row" rows="#{bindings.DepartmentsView1.rangeSize}" emptyText="#{bindings.DepartmentsView1.viewable ? 'No data to display.' : 'Access Denied.'}" fetchSize="#{bindings.DepartmentsView1.rangeSize}" rowBandingInterval="1" selectedRowKeys="#{bindings.DepartmentsView1.collectionModel.selectedRow}" selectionListener="#{bindings.DepartmentsView1.collectionModel.makeCurrent}" rowSelection="single" id="t1" styleClass="AFStretchWidth" binding="#{pageFlowScope.FilterProgrammaticBean.deptTabBind}" filterModel="#{bindings.DepartmentsView1Query.queryDescriptor}" queryListener="#{bindings.DepartmentsView1Query.processQuery}" filterVisible="true" varStatus="vs"> <af:column sortProperty="#{bindings.DepartmentsView1.hints.DepartmentId.name}" sortable="true" headerText="#{bindings.DepartmentsView1.hints.DepartmentId.label}" id="c1" filterable="true"> <af:inputText value="#{row.bindings.DepartmentId.inputValue}" label="#{bindings.DepartmentsView1.hints.DepartmentId.label}" required="#{bindings.DepartmentsView1.hints.DepartmentId.mandatory}" columns="#{bindings.DepartmentsView1.hints.DepartmentId.displayWidth}" maximumLength="#{bindings.DepartmentsView1.hints.DepartmentId.precision}" shortDesc="#{bindings.DepartmentsView1.hints.DepartmentId.tooltip}" id="it1" readOnly="true"> <f:validator binding="#{row.bindings.DepartmentId.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.DepartmentsView1.hints.DepartmentId.format}"/> </af:inputText> </af:column> <af:column sortProperty="#{bindings.DepartmentsView1.hints.DepartmentName.name}" sortable="true" headerText="#{bindings.DepartmentsView1.hints.DepartmentName.label}" id="c2" filterable="true"> <af:inputText value="#{row.bindings.DepartmentName.inputValue}" label="#{bindings.DepartmentsView1.hints.DepartmentName.label}" required="#{bindings.DepartmentsView1.hints.DepartmentName.mandatory}" columns="#{bindings.DepartmentsView1.hints.DepartmentName.displayWidth}" maximumLength="#{bindings.DepartmentsView1.hints.DepartmentName.precision}" shortDesc="#{bindings.DepartmentsView1.hints.DepartmentName.tooltip}" id="it2" readOnly="true"> <f:validator binding="#{row.bindings.DepartmentName.validator}"/> </af:inputText> </af:column> <af:column sortProperty="#{bindings.DepartmentsView1.hints.ManagerId.name}" sortable="true" headerText="#{bindings.DepartmentsView1.hints.ManagerId.label}" id="c3" filterable="true"> <af:inputText value="#{row.bindings.ManagerId.inputValue}" label="#{bindings.DepartmentsView1.hints.ManagerId.label}" required="#{bindings.DepartmentsView1.hints.ManagerId.mandatory}" columns="#{bindings.DepartmentsView1.hints.ManagerId.displayWidth}" maximumLength="#{bindings.DepartmentsView1.hints.ManagerId.precision}" shortDesc="#{bindings.DepartmentsView1.hints.ManagerId.tooltip}" id="it3" readOnly="true"> <f:validator binding="#{row.bindings.ManagerId.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.DepartmentsView1.hints.ManagerId.format}"/> </af:inputText> </af:column> <af:column sortProperty="#{bindings.DepartmentsView1.hints.LocationId.name}" sortable="true" headerText="#{bindings.DepartmentsView1.hints.LocationId.label}" id="c4" filterable="true"> <af:inputText value="#{row.bindings.LocationId.inputValue}" label="#{bindings.DepartmentsView1.hints.LocationId.label}" required="#{bindings.DepartmentsView1.hints.LocationId.mandatory}" columns="#{bindings.DepartmentsView1.hints.LocationId.displayWidth}" maximumLength="#{bindings.DepartmentsView1.hints.LocationId.precision}" shortDesc="#{bindings.DepartmentsView1.hints.LocationId.tooltip}" id="it4" readOnly="true"> <f:validator binding="#{row.bindings.LocationId.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.DepartmentsView1.hints.LocationId.format}"/> </af:inputText> </af:column> </af:table> </af:form> </af:document> </f:view> </jsp:root>
Managed Bean Code-
package filter.view; import java.util.Map; import javax.faces.event.ActionEvent; import oracle.adf.view.rich.component.rich.data.RichTable; import oracle.adf.view.rich.component.rich.input.RichInputText; import oracle.adf.view.rich.context.AdfFacesContext; import oracle.adf.view.rich.event.QueryEvent; import oracle.adf.view.rich.model.FilterableQueryDescriptor; public class FilterProgrammaticBean { private RichInputText deptNmBind; private RichTable deptTabBind; public FilterProgrammaticBean() { } public void setDeptNmBind(RichInputText deptNmBind) { this.deptNmBind = deptNmBind; } public RichInputText getDeptNmBind() { return deptNmBind; } public void setDeptTabBind(RichTable deptTabBind) { this.deptTabBind = deptTabBind; } public RichTable getDeptTabBind() { return deptTabBind; } /**Method to invoke FilterableQueryDescriptor and Filter Department table * @param actionEvent */ public void filterTableAction(ActionEvent actionEvent) { RichTable tbl = this.getDeptTabBind(); FilterableQueryDescriptor filterQD = (FilterableQueryDescriptor)tbl.getFilterModel(); Map filterCriteria = filterQD.getFilterCriteria(); filterCriteria.put("DepartmentName", deptNmBind.getValue()); getDeptTabBind().queueEvent(new QueryEvent(getDeptTabBind(), filterQD)); AdfFacesContext.getCurrentInstance().addPartialTarget(this.getDeptTabBind()); } }
Run your Application-
Cheers- Download Sample App
is there a new approach available as the getFilterCriteria method is now Deprecated in FilterableQueryDescriptor
ReplyDeleteYou can use getFilterConjunctionCriterion instead of getFilterCriteria method
DeleteSO i was trying to do this
DeleteRichTable tbl = this.getTable();
FilterableQueryDescriptor filterQD = (FilterableQueryDescriptor)tbl.getFilterModel();
ConjunctionCriterion cc = filterQD.getFilterConjunctionCriterion();
the variable "cc" gives me null value. what am I missing ?
and I am using jdev 11.1.1.9.0
DeleteUser
Deletecheck this about usage of - getFilterConjunctionCriterian
and make sure to set filterable true for af:table
Hi, Yes I did filtermodel, filterVisible is set on the Table and the af column has filterable property set to true as well. Still it doesnt works.
ReplyDeleteFilterableQueryDescriptor queryDescriptor = (FilterableQueryDescriptor) getSearchTabBind().getFilterModel();
that queryDescriptor always return null for me.
User
DeleteI have checked same code in Jdeveloper 12.1.3 and it is working for me, I am not sure what you have done wrong
Is your table based on ViewObject or it is pojo based ?
Ashish
Table is based on Viewobject ( I am on version 11.1.1.9.0 though )
Deletehow to change the default filter used in the table and use acustom viewcriteria to filter the table
ReplyDelete