1
votes

Is there a way to access properties of a child resource using Sling API ? I know with JCR API it is possible to access child nodes. Sling does give a way to list Children. But

Resource pageResource = resolver.getResource("/content/sitename/page/jcr:content");
ModifiableValueMap map = pageResource.adaptTo(ModifiableValueMap.class);
map.put("component01/propertyName","Changed Text");

doesn't work. This throws an 'Invalid Property' SlingException. Any suggestions ?

1
I believe its "" and not “” (quotes) . - Sabya
The complete stack trace and exception message would be useful. - Robert Munteanu

1 Answers

0
votes

doesn't work. This throws an 'Invalid Property' SlingException.

The quotes (“”) seem to be little fishy as I mentioned in the comment.

Try the following snippet .

You can fiddle around with these kind of requirements with the beautiful AEM Fiddle by ACS Tools.

Resource pageResource = resourceResolver.getResource("/content/sitename/page/jcr:content");
Iterable<Resource> childrenResources = pageResource.getChildren(); // Gives you all the resources representing direct children of /content/sitename/page/jcr:content 

for(Resource childResource : childrenResources){
    ModifiableValueMap mValueMap = childResource.adaptTo(ModifiableValueMap.class); // childResource should represent "component01"  .
    mValueMap.put("someProperty", "Some Value");
}