PrimeFaces Tree can be filtered by providing 'filterBy' attribute of tree tag. Let's see an example how to do that.
<h:form> <p:tree value="#{treeBean.treeNode}" var="node" filterBy="#{node}"> <p:treeNode> <h:outputText value="#{node}"/> </p:treeNode> </p:tree> </h:form>
@ManagedBean @ViewScoped public class TreeBean { private TreeNode treeNode; public TreeBean() { treeNode = new DefaultTreeNode("Employees", null); DataFactory dataFactory = new DataFactory(); for (int i = 0; i < 5; i++) { String[] employees = new String[10]; for (int j = 0; j < 10; j++) { employees[j] = dataFactory.getName(); } String company = dataFactory.getBusinessName(); addNode(treeNode, company, employees); } } private void addNode(TreeNode parentNode, String nodeName, String... children) { TreeNode node = new DefaultTreeNode(nodeName, parentNode); node.setExpanded(true); if (children != null) { for (String child : children) { addNode(node, child, null); } } } public TreeNode getTreeNode() { return treeNode; } }
To try examples, run embedded tomcat (configured in pom.xml of example project below):
mvn tomcat7:run-war
Dependencies and Technologies Used: