NeverEnding
NeverEnding

Reputation: 1

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

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();
        }

Upvotes: 0

Views: 360

Answers (1)

Jasper Floor
Jasper Floor

Reputation: 553

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).

Upvotes: 0

Related Questions