javax.jcr.node: How to use orderBefore function? | Community
Skip to main content
jayv25585659
September 3, 2020
Solved

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

  • September 3, 2020
  • 1 reply
  • 2376 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by VeenaVikraman

@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.lang.String,%20java.lang.String)

 

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

 

1 reply

VeenaVikraman
Community Advisor
VeenaVikramanCommunity AdvisorAccepted solution
Community Advisor
September 3, 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.lang.String,%20java.lang.String)

 

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