How to rename a JCR Node without changing its position programmatically?

315 Views Asked by At

I have used the below to rename the node but is their a way to avoid changing the position?

    void rename(Node node, String newName) throws RepositoryException 
        {
            node.getSession().move(node.getPath(), node.getParent().getPath() + "/" + newName);
             node.getSession().save();
        }
1

There are 1 best solutions below

0
Jasper Floor On

Nodes can be ordered if the parent node supports child node ordering. When you rename a node, you will need to move it back. Basically, get the parent node, ask for the child nodes, iterate over them until you find the node you want to come after this one, then call node.orderBefore(renamedNode, nextSibling).