Here, we will see how to filter data using view criteria.
1. Create a simple view criteria and apply on the view object to filter data.
2. Clear the filter condition by removing the applied view criteria.
3. Programmatically create a view criteria.
Note the following APIs related to View Criteria:
* getViewCriteria(“EmployeeViewCriteria”) — This will return the view criteria object.
* applyViewCriteria(vc) — Applies the view criteria on the view object
* removeApplyViewCriteriaName(“EmployeeViewCriteria”) — Removes the applied view criteria from the view object
1. Create a simple view criteria and apply on the view object to filter data.
Double click the View Object on the application navigator. Select Query and add a view criteria.
As shown, select the attribute(Dept), the operator and a bind parameter.
Open the ViewImpl java file and write the following code to create a method. This method will fetch the view criteria and sets the bind parameters. Finally, executes the criteria to apply on the view object.
public void searchEmployee(String dept) {
ViewCriteriaManager vcm = getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria(“EmployeeViewCriteria”);
vc.resetCriteria();
this.setdept(dept);
this.applyViewCriteria(vc);
this.executeQuery();
}
Open the client interface for the View Object and select the method to be exposed in the data control.
Select and drag the searchEmployee from the data control to test1PG.jspx and select ADF Parameter Form.
Drag the EmployeeView to the page to create a table.
Run the page to test. Supply some department name and click the search button to apply the view criteria and the filtered data will be displayed.
2. Remove the applied View Criteria
Now, write the following piece of code to create a method which will remove the criteria that we just applied.
public void clearSearchEmployee() {
this.removeApplyViewCriteriaName(“EmployeeViewCriteria”);
this.executeQuery();
}
As done earlier, expose the created method in data control.
Drag the method to the page to create an ADF button.
Run the page to test again. First, filter data by applying the view criteria. Now, clear the criteria by hitting the newly created button.
3. Programatically create a view criteria.
Now, we will see how to create a view criteria programmatically and apply on the view object.
The following code does the work.
public void progEmployeeCriteria(String dept) {
ViewCriteria vc = this.createViewCriteria();
ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
ViewCriteriaItem jobItem = vcRow.ensureCriteriaItem(“Dept”);
jobItem.setOperator(“=”);
jobItem.getValues().get(0).setValue(dept);
vc.add(vcRow);
this.applyViewCriteria(vc);
this.executeQuery();
}
Here, Dept is the View Object attribute name and dept is the user input.
Let’s expose this method in the data control and create an ADF parameter form on the screen.
ليست هناك تعليقات:
إرسال تعليق