javax.jcr.node: How to use orderBefore function?

Avatar

Avatar

jayv25585659

Avatar

jayv25585659

jayv25585659

03-09-2020

I have the following path:

 

    /content/mysite/en/jcr:content/content/section/par_0
    /content/mysite/en/jcr:content/content/section/par_1
        /content/mysite/en/jcr:content/content/section/par_1/oldnode

 

I want to add another node before the RTE node. It seems I need to be using orderBefore function but I cannot get it to work.

 

I tried

Node mynode = session.getNode("/content/mysite/en/jcr:content/content/section/par_1);

mynode.orderBefore("oldnode", "newnode")

 

and I'm getting a "not a child error".

 

Any ideas? Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Veena_Vikram

MVP

Avatar

Veena_Vikram

MVP

Veena_Vikram
MVP

03-09-2020

@jayv25585659 For orderBefore to work properly , 

 

Node mynode = session.getNode("/content/mysite/en/jcr:content/content/section/par_1);

mynode.orderBefore("oldnode", "newnode")

 

Your myNode should be the parent node , and first argument should be your node name ( you want to insert) and second argument should be the the node name immediately below which you want to insert it. 

 

https://docs.adobe.com/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#orderBefore(java.lan...

 

orderBefore

void orderBefore(java.lang.String srcChildRelPath,
                 java.lang.String destChildRelPath)
                 throws UnsupportedRepositoryOperationException,
                        VersionException,
                        ConstraintViolationException,
                        ItemNotFoundException,
                        LockException,
                        RepositoryException

If this node supports child node ordering, this method inserts the child node at srcChildRelPath into the child node list at the position immediately the child node at destChildRelPath.

To place the node srcChildRelPath at the end of the list, a destChildRelPath of null is used.

 

 

Also please refer some sample her https://www.codota.com/code/java/methods/javax.jcr.Node/orderBefore

Hope this helps

 

Thanks

Veena

 

Answers (0)