0
votes

I'm looking for a way to retrieve all the components and their properties on page using the USE api in ADOBE AEM.

There is very little documentation but from what I can see I should be able to use the listChildren but this doesn't seem to be working.

eg

currentPage.listChildren()

Just seems to be returning its child pages.

1

1 Answers

0
votes

Assuming that you have a container component where you drag and drop components on page like a parsys and you want list of all components dropped in the parsys, you could do something like this (assuming par is the node name for parsys) -

Iterable<Resource> droppedComponents = () -> currentPage.getContentResource().getResource("par").listChildren();

final Stream<Resource> resultStream = StreamSupport.stream(droppedComponents.spliterator(), false);
        List<ValueMap> compPropertyList = resultStream.map(resource -> resource.adaptTo(ValueMap.class))
                .collect(Collectors.toList());
        resultStream.close();

if you want all the components directly under the page, in above remove getResource("par")