Expand my Community achievements bar.

SOLVED

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

Avatar

Level 8

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

@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