tree filter is not working right when there are more than 10 nodes

Components, Ajax Framework, Utilities and More.
Post Reply
User avatar
tefron
Posts: 76
Joined: 15 Sep 2010, 23:54
Location: Canada
Contact:

20 Apr 2017, 19:39

The tree filter is very nice, however, when the tree contain many nodes it doesn't filter them right.

The code:

Code: Select all

	public void encodeTreeNode(FacesContext context, Tree tree, TreeNode node, String clientId, boolean dynamic, boolean checkbox, boolean dragdrop) throws IOException {
        //preselection
        String rowKey = node.getRowKey();
        boolean selected = node.isSelected();
        boolean partialSelected = node.isPartialSelected();
        boolean filter = (tree.getValueExpression("filterBy") != null);

        UITreeNode uiTreeNode = tree.getUITreeNodeByType(node.getType());
        if(!uiTreeNode.isRendered()) {
            return;
        }
        
        List<String> filteredRowKeys = tree.getFilteredRowKeys();
        boolean match = false;
        if(filter && filteredRowKeys.size() > 0) {
            for(String rk : filteredRowKeys) {
                if(rk.startsWith(rowKey) || rowKey.startsWith(rk)) {
                    match = true;
                    if(!node.isLeaf() && !rowKey.startsWith(rk)) {
                        node.setExpanded(true);
                    }
                    break;
                }
            }
            
            if(!match) {
                return;
            }
        }   

The check:
if(rk.startsWith(rowKey) || rowKey.startsWith(rk))

is wrong in my case there is a node that was matched with id: 0_101 and this check match also node with other ids e.g.: 0_1

I understand the logic of this check (matching parents of matched nodes) but it doesn't work in this case and in general I don't thing its a very good idea to put to many assumptions and logic into the id structure. The id should be unique and 'dumb' so it could be overridden easily by applications.
PrimeFaces: primefaces-6.1.RC1
Mojara2.1.13
Netbeans8.2
wildfly-10.1.0.Final

User avatar
tefron
Posts: 76
Joined: 15 Sep 2010, 23:54
Location: Canada
Contact:

20 Apr 2017, 22:11

The following code change works for me:

Code: Select all

        if (filter && filteredRowKeys.size() > 0) {
            for (String rk : filteredRowKeys) {
                String rowKeyExt = rowKey + "_";
                String rkExt = rk + "_";
                if (rk.startsWith(rowKeyExt) || rowKey.startsWith(rkExt) || rk.equals(rowKey)) {
                    match = true;
                    if (!node.isLeaf() && !rowKey.startsWith(rk)) {
                        node.setExpanded(true);
                    }
                    break;
                }
            }
You should test it for other use case of course.
PrimeFaces: primefaces-6.1.RC1
Mojara2.1.13
Netbeans8.2
wildfly-10.1.0.Final

kukeltje
Expert Member
Posts: 8473
Joined: 17 Jun 2010, 13:34
Location: Netherlands

21 Apr 2017, 10:26

Good find, please file an issue in github
Ronald van Kuijk
______________________________
PrimeFaces 5.2, PrimeFaces plus 0.0.2 | JbossWildfly 8.1| Mojarra 2.2.8
Fedora 21, Firefox 'most recent'
Read the forum posting rules
Beginners: https://jsf.zeef.com/bauke.scholtz

User avatar
Melloware
Posts: 205
Joined: 22 Apr 2013, 15:48

22 Apr 2017, 14:39

If you file the issue in Github I will fix it with a PR.
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces 6.1 / PF Extensions 6.1.0

User avatar
Melloware
Posts: 205
Joined: 22 Apr 2013, 15:48

24 Apr 2017, 17:08

PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces 6.1 / PF Extensions 6.1.0

Post Reply
  • Information
  • Who is online

    Users browsing this forum: Bing [Bot], Google [Bot], pjahu and 15 guests