Solved
How to move a node to top in a container programatically?
I have a container in which three nodes are present. I want to rearrange the 2nd node to the top position in the container. How can I do this programmatically?
I have a container in which three nodes are present. I want to rearrange the 2nd node to the top position in the container. How can I do this programmatically?
you can utilize the orderBefore API to achieve the same.
private void orderAsFirstChild(String childName, Node parentNode) throws RepositoryException {
if (parentNode.hasNode(childName)) {
// find current first child name
String firstChildName = Optional.ofNullable(parentNode.getNodes())
.map(NodeIterator::nextNode)
.map(node -> {
try {
node.getName();
} catch (RepositoryException e) {
e.printStackTrace();
}
return (String) null;
}) //
.orElse(null);
parentNode.orderBefore(childName, firstChildName);
}
}
Src: https://stackoverflow.com/questions/55239195/programmatically-arranging-contents-in-aem-6-4
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.