Quantcast

Add Node in a Leaf Node using Ajax

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Add Node in a Leaf Node using Ajax

sanjay
Hello,

I have a BaseTree with a Panel shown at the TreeNode. Each TreeNode Panel has a Label and Ajax Button. On click of this button, a New node gets added in the same node.

When I am trying to add New TreeNode in a Leaf Node, it is not working properly. The model gets changed but UI is not showing the Leaf node as a non-leaf node. I have to collapse the Parent node and reopen it. This works perfectly fine for Non-leaf nodes.

Below is the way I am adding new node.

public void onClick(AjaxRequestTarget target ) {

  BaseTree tree = (BaseTree) get("tree");
  DefaultTreeModel treeModel = (DefaultTreeModel) tree.getDefaultModelObject();
 
  DefaultMutableTreeNode parentNode = findParentNode(treeModel);//Custom method to find parent.

  if (parentNode.isLeaf()) {
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    dummyNode.setUserObject(itemModel); //itemModel contains properties for newNode

    int[] changes =
        new int[] { model.getIndexOfChild(parentNode, dummyNode) };
    treeModel.nodesWereInserted((DefaultMutableTreeNode) parentNode, changes);

    tree.updateTree(target);
    target.addComponent(tree);
  }

}


I tried various methods to refresh the parent node in this case. But none of them worked. Like as shown below,
treeModel.reload();
treeModel.reload(parentNode);
treeModel.nodeStructureChanged((DefaultMutableTreeNode) parentNode);
tree.getTreeState().expandNode(parentNode);

Can any one please tell me if I am missing any thing? The same code work properly for Non-leaf nodes.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add Node in a Leaf Node using Ajax

sanjay
Loading...