question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tree: search does not show all matching nodes

See original GitHub issue

1) 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: image

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.

image

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:closed
  • Created 4 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
f-r-a-n-scommented, Sep 2, 2019

Let me see if I can propose something.

0reactions
f-r-a-n-scommented, Sep 4, 2019

PR created: #5109

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found