Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new

Learn more

View all

Sign in to view all badges

Sling model – Retrieving properties of child resources | AEM Community Blog Seeding

Community Manager
Community Manager


Sling model – Retrieving properties of child resources by Kiran


In AEM, we fetch the values of multiple properties via java code and display them in HTL.

Common Way of fetching the properties:

Resource resource = resourceResolver.getResource(request.getParameter("resourcePath"));
//Adapting the resource to a node
//Adapting the resource to an asset
//Adapting the resource to valuemap
resource.adaptTo(ValueMap.class).get("propertyName", String.class);
There are many other adapters available that we can adapt a resource with. You can check them here.

Fetching the property values of a sub-resources becomes complex here. So, lets discuss a simpler way to resolve this problem.

Create a new sling model:

Let’s create a new model with the properties that we need from the child nodes. In the below example, the resource is an asset.

@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ChildResourceModel {

private String title;

private String description;

private String name;

public String getTitle() {
return title;

public String getDescription() {
return description;

public String getName() {
return name;


Read Full Blog

Sling model – Retrieving properties of child resources


Please use this thread to ask the related questions.

2 Replies
Level 5
Level 5

If we can create a model for child resource and adapt it in the main model class then what is the use of 

@Via(type = ResourceSuperType.class) ?


We have in built ResourceSuperType.class and annotation @Via.

 What are the advantageous in using the above pattern?


Level 4
Level 4

Very nice way of using @Named annotation

Advantages of this approach:

  1. Can re-use the model
  2. Less code
  3. Can enhance it to add multiple properties
  4. Can be iterated over multiple resources