When you are working on trees in ADF, sometimes we get some requirement like performing a search in the tree.
In this post, I will explain the search implementation in the tree constructed on Departments and Employees.
Here, I implemented the search on employee first name.
In this post, I will explain the search implementation in the tree constructed on Departments and Employees.
Here, I implemented the search on employee first name.
As you can see in the above screenshot, The user searched for Employee name containing "n". In the below panel, Only the departments which have employees containing "n" are disclosed. And the matching results are highlighted in green and bold for easy identification.
Implementing search in a tree is not as easy as implementing in a table. This post explains the steps briefly.
1. Constructing a tree is direct simple way. Have a DepartmentVO and an EmployeeVO and a view link for the relationship between them. Drop the DepartmentVO as an ADF tree in the UI. In the tree level rules, add the EmployeeVO and click Ok.
2. On search, add an actionListener. The code shown below:
Here, we call a method recursiveSearch() which return matching rowKeySet. Implementation will follow up next. And we are maintaining the employees list to show the green coloring in UI. Process will be shown later in the post. And a method buildDisclosedRowSet(:p,:p) and then set the disclosedRowKeys to open the department tree nodes having the matching results. And then refresh the tree.
3. recursiveSearch() method
We are iterating through the tree starting from the root node. (which will have all departments, every tree will have this by default) and if it is an employee row, we are checking for the matching results and return the complete list.
4. buildDisclosedRowSet() method
Here we are preparing the disclosedRowSet to setDisclosedRowKeys for the tree. This is done by constructing the path (by getting parents till root) as shown above.
5. Green color in the UI.
Bind the inline style property of the outputText in UI to bean as shown below.
In the getter of this String inlineStyleForNode, write the below code.
The employees list prepared in the action event is used here to compare with the outputText value.
If it matches, we color in green.
Hope this helps :)
No comments:
Post a Comment