List<ExistingPagesModel> pagesList = new ArrayList<>();
Resource parentResource = resourceResolver.getResource("/content/us/en/home/test");
if (parentResource != null) {
Iterator<Resource> childResources = parentResource.listChildren();
log.info("childResources: {}");
while (childResources.hasNext()) {
Resource childResource = childResources.next();
log.info("Processing child resource: {}", childResource.getPath());
// Get property values from child resource
childTitle = childResource.getValueMap().get("jcr:content/jcr:title", String.class);
childDescription = childResource.getValueMap().get("jcr:content/jcr:description", String.class);
String childImage = childResource.getValueMap().get("cq:featuredimage/fileReference", String.class);
// childImage = getChildImageFromResource(childResource);
log.info("Child Title: {}", childTitle);
log.info("Child Description: {}", childDescription);
log.info("childImage: {}", childImage);
if (childTitle != null) {
// Create an ExistingPagesModel object for each child page
ExistingPagesModel pageInfo = childResource.adaptTo(ExistingPagesModel.class);
if (pageInfo != null) {
pageInfo.setChildTitle(childTitle);
pageInfo.setChildDescription(childDescription);
pageInfo.setChildImage(childImage);
pagesList.add(pageInfo);
}
}
}
}
log.info("pageInfo: {}", pagesList);
return pagesList;
}
title and description are working but in childImage i am getting null can someone help me with that?