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?
Solved! Go to Solution.
Views
Replies
Total Likes
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
Hi @SahilDh1,
I've never tried it, but there seems to be an API for re-ordering: https://developer.adobe.com/experience-manager/reference-materials/spec/jsr170/javadocs/jcr-2.0/inde...
Good luck,
Daniel
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
@SahilDh1 Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies