April 14, 2020
Estimated Post Reading Time ~

Working with Sling Models in Adobe Experience Manager

You can work with Sling Models when developing with Adobe Experience Manager (AEM). That is, when developing an AEM project, you can define a model object, which is a Java object that is mapped to a Sling object, typically resources, but also request objects. A Sling Model is implemented as an OSGi bundle.

A Java class located in the OSGi bundle is annotated with @Model and the adaptable class. The data members (Fields) use the @Inject annotation. Consider the following Java class.

package org.kalyan.poc.sling.models;

import javax.inject.Inject;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;

@Model(adaptables = Resource.class)
public class UserInfo {
@Inject
private String firstName;
@Inject
private String lastName;
@Inject
private String technology;

public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getTechnology() {
return technology;
}

}


As you can see the @Model annotation is used. Likewise, each data member in the UserInfo class is annotated using @Inject. For more information about Sling Models, see Sling Models.

This article walks you through creating an AEM application that uses Sling Models. 



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.