[ 
https://issues.apache.org/jira/browse/WICKET-2888?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12907366#action_12907366
 ] 

Pedro Santos commented on WICKET-2888:
--------------------------------------

Moving an node from the tree last position makes that the tree component marks 
the new last node as dirty, since it's visualization will change, from "-" to 
"L" (see AbstractTree#markTheLastButOneChildDirty).
At the rob described case, after remove the last node, it is added to the new 
last node as an child.
The problem was that treeNodesInserted method marks the new last node as dirty 
and recreate it, at the same time it marks the old last node to DOM creation 
because it was inserted at some node.
Then at "onTargetRespond" method, the new recreated last node will receive new 
TreeItem children. In the next step, the method will try to send the DOM 
creation script for the old last tree node. But it was already recreated, and 
has no parent at the time (the parent was correctly setted on the new last node 
children only).
I was able to fix this bug only by coordinating the execution sequence and 
maintain the dirty components list updated. (sending an patch)



> Nullpointer when inserting [i.e. moving] a node in a TreeTable (AbstactTree, 
> treeNodesInserted)
> -----------------------------------------------------------------------------------------------
>
>                 Key: WICKET-2888
>                 URL: https://issues.apache.org/jira/browse/WICKET-2888
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket, wicket-extensions
>    Affects Versions: 1.4.2
>         Environment: On Linux, AMD64
>            Reporter: r...@audenaerde.org
>         Attachments: tree-quickstart.tar.gz
>
>
> A have a simple tree:
> root
> -c1
> --cc1
> -c2
> --cc2
> -c3
> I want to move c3 from parent root to parent c2. This works when the treenode 
> c2 is not expanded, i.e. cc2 is not shown. When c2 is expanded, the action 
> results in a nullPointerException in treeNodesInserted. The cause of the 
> nullPointer is:
> parentItem.getChildren() <-- returns null, but in line 845 the 
> parentItem.getChildren().add() is called, thus the nullPointer.
> Any hints?
> my piece of tree manipulation code:
>                table.getTreeTable().modelChanging();
>                 DefaultTreeModel model = (DefaultTreeModel) 
> table.getTreeTable().getDefaultModelObject();
>                 DefaultMutableTreeNode parent = (DefaultMutableTreeNode) 
> myNode.getParent();
>                 // getIndexOfChild returns -1 if either of th nodes == null
>                 int myIndex = model.getIndexOfChild( parent, myNode );
>                 if ( myIndex < 1 ) // 0 or -1
>                 {
>                     return;
>                 }
>                 DefaultMutableTreeNode previousSibling = 
> (DefaultMutableTreeNode) model.getChild( parent, myIndex - 1 );
>                 model.removeNodeFromParent( myNode );
>                 //insert the node as last
>                 model.insertNodeInto( myNode, previousSibling, 
> model.getChildCount( previousSibling ) );
>                 table.getTreeTable().modelChanged();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to