Inject Child Pages using Sling Models | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by gopalKa

What is your usecase. Injecting child resource is possible. Please refer to https://sling.apache.org/documentation/bundles/models.html

List injection for child resources works by injecting grand child resources (since Sling Models Impl 1.0.6). For example, the class

@Model(adaptables=Resource.class)public class MyModel {@Injectprivate List<Resource> addresses;}

Is suitable for a resource structure such as:

+- resource (being adapted)|+- addresses|+- address1|+- address2

In this case, the addresses List will contain address1 and address2.

3 replies

francisco_ribei
Level 6
October 16, 2015

Hi @kalyanar,

I would like to have a class that I would adapt from Page, and wanted that its children were already injected, to not need to call listChildren.

Thanks

gopalKaAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

What is your usecase. Injecting child resource is possible. Please refer to https://sling.apache.org/documentation/bundles/models.html

List injection for child resources works by injecting grand child resources (since Sling Models Impl 1.0.6). For example, the class

@Model(adaptables=Resource.class)public class MyModel {@Injectprivate List<Resource> addresses;}

Is suitable for a resource structure such as:

+- resource (being adapted)|+- addresses|+- address1|+- address2

In this case, the addresses List will contain address1 and address2.

smacdonald2008
Level 10
October 16, 2015

For Sling Models - see these Apache docs:

https://sling.apache.org/documentation/bundles/models.html#custom-injectors 

I have not seen too many examples of using Sling Models in AEM. I will determine if we have examples internally.