Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:48:31+00:00 2026-06-08T02:48:31+00:00

I am developing a Tree component, which might be prunned according to the user

  • 0

I am developing a Tree component, which might be prunned according to the user input. I have all nodes cached, in order to provide primefaces component model with always the same instances of the tree nodes.

But the problem is, that when I change the parent-child relationships (remove some of them), I always get a concurrent modification exception… Is there any way to workaround this issue or am I missing something.

Thanks in advance.

/**
 * Recursively copy the hierarchy and prune not visible branches
 * @param originalNode node of the original hierarchy to be copied
 * @param parent parent node in the new hierarchy
 * @param visibleNodes set of nodes, which should be included in the new hierarchy
 * @param model model of the TreeAutompleteComponent
 * @return copy of the oroginal node in the new hierarchy
 */
private TreeNode copyHierarchy(TreeNode originalNode, TreeNode parent, Set<TreeNode> visibleNodes, TreeAutocompleteModel model) {
    if (!visibleNodes.contains(originalNode)) {
        return null;
    }

    TreeNode newNode = model.getCompleteModelNodes().get(((NodeWrapper)originalNode.getData()).getIri());//new DefaultTreeNode(originalNode.getData(), parent);
    for (int i = 0; i < originalNode.getChildCount(); i++) {
        copyHierarchy((TreeNode) originalNode.getChildren().get(i), newNode, visibleNodes, model);
    }
    newNode.setParent(parent); //when removed, no exception occurs
    return newNode;
}

The exception

ava.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
    at java.util.ArrayList$Itr.next(ArrayList.java:791)
    at org.primefaces.component.tree.TreeRenderer.encodeTreeNodeChildren(TreeRenderer.java:284)
    at org.primefaces.component.tree.TreeRenderer.encodeTreeNode(TreeRenderer.java:274)
    at org.primefaces.component.tree.TreeRenderer.encodeMarkup(TreeRenderer.java:165)
    at org.primefaces.component.tree.TreeRenderer.encodeEnd(TreeRenderer.java:96)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:48:32+00:00Added an answer on June 8, 2026 at 2:48 am

    This is solution, that works. I havent localized the actual issue, but I have sucessfully workaround all it…

    public TreeNode constructActualModel(TreeAutocompleteMatcherIface matcher) {
        if (prunedModel == null) {
            eraseHierarchyStructure();
            prunedModel = copyHierarchy((TreeNode) completeModel, getVisibleNodes(matcher));
        }
        return prunedModel;
    }
    
    /**
     * Recursively copy the hierarchy and prune not visible branches
     * @param originalNode node of the original hierarchy to be copied
     * @param visibleNodes set of nodes, which should be included in the new hierarchy
     * @param model model of the TreeAutompleteComponent
     * @return copy of the oroginal node in the new hierarchy
     */
    private TreeNode copyHierarchy(TreeNode originalNode, Set<TreeNode> visibleNodes) {
        if (!visibleNodes.contains(originalNode)) {
            return null;
        }
    
        TreeNode newNode = this.getCompleteModelNodes().get(((NodeWrapper) originalNode.getData()).getIri());//new DefaultTreeNode(originalNode.getData(), parent);
        List<TreeNode> children = new ArrayList<TreeNode>();
        for (int i = 0; i < originalNode.getChildCount(); i++) {
            TreeNode child = copyHierarchy((TreeNode) originalNode.getChildren().get(i), visibleNodes);
            if(child != null){
                children.add(child);
            }
        }
        ((DefaultTreeNode) newNode).setChildren(children);
        return newNode;
    }
    
    private void eraseHierarchyStructure() {
        for (TreeNode node : duplicateCompleteModelNodes.values()) {
            node.setParent(null);
        }       
    }
    

    It was necessary to do it the opposite way – to get the impl to be able to call the setChildren method and at first erase the hierarchy…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a programming language for which I want to provide a Range data
I am developing publishing site and it will have complex tree structure. Is there
I am developing an application which contains controls like tree,grid and chart. I personally
I am developing an application that uses JS Tree with json data and ajax
I'm developing a simple WPF explorer tree. Sacha Barber wrote a good article about
I'm developing a Linux kernel module outside of the Linux source tree (in the
i'm developing a windows form application.in the form, the left part is a tree
Developing for Android 2.3, I have a question regarding layouts. I use a vertival
Developing a project of mine I realize I have a need for some level
I am currently developing an embedded uP based appliance which can be remotely controlled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.