Hi @zendarkke
If your container resource structure does contain an intermediate node that would in turn contain the card1, card2, card3 and so on, then the solutions you already received describe how you can map the children.
But if it does not, which I believe is your case, then the only thing you can do (as far as I know) is to write a code in your @PostConstruct method, get all the children from the current resource (the container), take only those matching the resourceType of a card and put in a list on the model class.
Not the best, but here is an example:
import java.util.List;
import java.util.Optional;
import javax.annotation.PostConstruct;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
@Model(adaptables = { Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ContainerComponentModel {
@Self
private Resource container;
private List<Resource> cards;
@PostConstruct
private void init() {
Optional.ofNullable(container)
.map(Resource::getChildren)
.ifPresent(children -> children.forEach(child -> {
if (child.isResourceType("your_card_resource_type")) {
cards.add(child);
}
}));
}
}
Or if you want to complicate things a little more, I found this example also: https://www.jeroendruwe.be/aem-children-sling-model-annotation