Tree: search does not show all matching nodes
See original GitHub issue1) Environment
- PrimeFaces version: 7.0.7
- Does it work on the newest released PrimeFaces version? No
- Does it work on the newest sources in GitHub? Not tried
- Application server + version: Tomcat 8.5.20
- Affected browsers: Firefox, Chrome, Edge
2) Expected behavior
When using filtering on a <p:tree>
, I expect the search to show all matching nodes, expanding all ancestor nodes to a matching one.
3) Actual behavior
When both a parent and a child nodes match, only the parent node is shown, i.e. the parent node is not expanded and as a result the child node is not directly visible (one has to expand the parent to see it).
4) Steps to reproduce
Here is a simple two-level tree:
If I start typing nut
in the search box, I see the nodes Capsule / Brazil nut
, Fibrous drupe / Coconut
, Fibrous drupe / Walnut
and top node Nut
(so far so good) but not its child node Hazelnut
.
Actually, Nut / Hazelnut
is present in the tree but the Nut
node is not expanded.
5) Sample XHTML
<p:tree value="#{treeBean.root}" var="node" filterBy="#{node}" filterMatchMode="contains">
<p:treeNode>
<h:outputText value="#{node}"/>
</p:treeNode>
</p:tree>
6) Sample bean
public class TreeBean {
private TreeNode root;
public TreeBean() {
this.root = new DefaultTreeNode();
this.root.getChildren().add(buildNode("Achene", "Strawberry"));
this.root.getChildren().add(buildNode("Capsule", "Brazil nut"));
this.root.getChildren().add(buildNode("Fibrous drupe", "Coconut", "Walnut"));
this.root.getChildren().add(buildNode("Legume", "Bean", "Pea", "Peanut"));
this.root.getChildren().add(buildNode("Nut", "Beech", "Hazelnut", "Oak acorn"));
this.root.getChildren().add(buildNode("Berry", "Cranberry", "Gooseberry", "Redcurrant", "Tomato"));
this.root.getChildren().add(buildNode("Drupe", "Apricot", "Cherry", "Olive", "Peach", "Plum"));
}
private TreeNode buildNode(String nodeName, String... childrenNames) {
TreeNode node = new DefaultTreeNode(nodeName);
for (String childName : childrenNames) {
node.getChildren().add(new DefaultTreeNode(childName));
}
return node;
}
public TreeNode getRoot() {
return root;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Find matching nodes in a tree with full path - Stack Overflow
You need to generate a new object with only the relevant parts. This proposal works iterative for a single level and recursive for...
Read more >display only nodes matching the search query (hide others ...
When I have very large tree and I'm searching if particular node - all others that do not match the search query are...
Read more >Search a node in Binary Tree - GeeksforGeeks
Given a Binary tree and a node. The task is to search and check if the given node exists in the binary tree...
Read more >How to expand children of matched nodes? - Google Groups
I am just guessing here: Another option might be to work with your "model" directly. Iterate over all model nodes and filter those...
Read more >Flexible Tree Matching - Tim Roughgarden
nodes and the insertion/deletion cost for nodes which are not matched. Given such a model, the tree-matching problem is to find a lowest-cost...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Let me see if I can propose something.
PR created: #5109