Développer ma barre des réalisations de la Communauté.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Cette conversation a été verrouillée en raison de son inactivité. Veuillez créer une nouvelle publication.

RÉSOLU

how to iterate on sling folders?

Avatar

Level 1

I want to iterate on the sling folder and get the information on it in java.

"SELECT * FROM [nt:base] AS s WHERE [jcr:primaryType]=\"sling:Folder\" AND ISDESCENDANTNODE([/etc/foldername]) and ...."

In java,

Iterator<Resource> queryResult = resolver.findResources("SELECT * FROM [nt:base] AS s WHERE [jcr:primaryType]=\"sling:Folder\" AND ISDESCENDANTNODE([/etc/foldername]) and ....", Query.JCR_SQL2);

while (queryResult.hasNext()) {

Resource res = queryResult.next();

//but here how to get the information stored on the sling folder

}

1489633_pastedImage_0.png

how to read the name and ID property values?

Please help me with this issue in accessing the ID and name stored in the sling folder.

1 solution acceptée

Avatar

Réponse correcte par
Employee Advisor

Do not use queries for that! Way too much overhead. Instead iterate directly the children list:

Resource folder = resourceResolver.getResource("/path/to/the/folder");

Iterator<Resource> children = folder.listChildren();

children.forEach (c ->

  ValueMap vm = c.adaptTo(ValueMap.class);

  String prop1 = vm.get("name", String.class);

  ...

);

Voir la solution dans l'envoi d'origine

2 Replies

Avatar

Réponse correcte par
Employee Advisor

Do not use queries for that! Way too much overhead. Instead iterate directly the children list:

Resource folder = resourceResolver.getResource("/path/to/the/folder");

Iterator<Resource> children = folder.listChildren();

children.forEach (c ->

  ValueMap vm = c.adaptTo(ValueMap.class);

  String prop1 = vm.get("name", String.class);

  ...

);

Avatar

Level 1

Thank you, it works!