1
votes

Once you've gotten a node from the JCR, what is the easiest way to get its previous and next siblings?

1

1 Answers

3
votes

Not entirely sure if its the easiest way but you may do something like that

    Node parent = node.getParent();
    NodeIterator siblings = parent.getNodes();
    Node firstSibling = siblings.nextNode();

For previous you should do some operations on siblings object but that should be straightforward. This would be the JCR way of doing that.

However, Magnolia has the helper functions which reside under info.magnolia.jcr.util.NodeUtil package

Then One may use the following;

NodeUtil#getSiblingBefore()
NodeUtil#getSiblingAfter()