Friday 11 April 2014

ADF : Filtering ListOfValues Effectively, Best way to filter an LOV

Hello all,

This is an initial level post, but still thinks can get tricky at times, so i thought of sharing this.

Here I will try to demonstrate how we can filter the values of an LOV effectively.
First we need to know about what happens when an LOV is added on an attribute in a viewObject.

When a LOV is added on an attribute then an instance of the viewObject ( which is used for creating LOV ) is created and that is added to the attribute as an LOV. This instance is attached to the parent viewObject.
Let us take an example,
Suppose we have to show departments in place of department Id in EmployeeViewObject made from Employees Table.
For doing so we will have create a viewObject containing DeptId and DepartmentName, we can name it LovDeptVO. Then we will select the departmentId field in EmployeeViewObject and add LOV and select LovDeptVO viewObject and do attribute mapping , at this time an instance of viewObject LovDeptVO is created and added to EmployeeViewObject. And then you can view the instance of the lov in viewAccessors Tab of EmployeeViewObject.

So now we come to filtering the LOV on somevalues.

There are two cases :

1. Filtering LOV with the attribute present in the same ViewObject.
We have to create a viewCriteria in the lov ViewObject and pass values to bind variables from the viewObject which contains the LOV.
Let us take an example ;

I have created an ADF Applcation with HR Schema.

Then created a temprory viewObject containing two attributes departmentId and EmployeeId.




Then we have to create EmployeeViewObject to make LOV from it.


Now go to Query Tab and create a viewCriteria filtering the LOVEmployeeVo with DeptId. So now LOV viewObject is also complete.

Now we have to make LOV in the EmployeeId in TempVO. Select the EmployeeId attribute go to ListOfValues section and add an lov by clicking add button.

Now we have to pass the selected DepartmentID to LOV so that i can be filtered. So go to the viewAccessors tab in TempVO. You will see the LOV instance there.
Click edit and pass the values. Drag the available viewCriteia to the left and pass the value to the bindVariable.


New Create a page and drop the TempVO as a form. Set Autosubmit value of DepartmentId field to true. And add partial trigger on EmployeeId attribute to refresh the LOV when value of Department changes.



2. Filtering LOV with the attribute present outside the ViewOject i.e. filtering LOV from outside.

So in the above case we had to filter the lov from the attribute from the ViewObject containing Lov, i mean EmployeeId and DepartmentId both fields were in the same ViewObject. How will we filter when we have to filter the LOV on the basis of value coming from a diffferent ViewObject.

For this purpose i created a text field on the page and created a button to filter the LOV.
For that I have created a method in AmImpl and called it in the bean by adding it to client interface.
Method in AMImpl .
And In Bean I have called the Method in AM


On Running the application


When DepartmentId is entered as 10 and filterLov button is clicked



You can download the sample Application here : LovTestApp.rar

No comments:

Post a Comment