#Adobe Experience Manager

What Are Models in AEM

Contents

Models in Adobe Experience Manager (AEM) refer to the Java representations of AEM content. They use the Sling Models framework, allowing developers to map resource properties onto Java objects.

Purpose of AEM Models

The primary purpose of AEM Models is to simplify accessing and manipulating content stored in the JCR (Java Content Repository) in AEM. By mapping content properties to Java objects, developers can work with AEM content as if they were working with plain old Java objects (POJOs).

Working Mechanism of AEM Models

AEM Models are created by defining a Java interface or class and annotating it with the @Model annotation. The properties of the AEM content can then be mapped to fields in the model using annotations such as @Inject and @ValueMapValue. Once the model is defined, it can be used in AEM components to access and manipulate the content.

Advantages of Using AEM Models

Using AEM Models provides several benefits. Firstly, they make code cleaner and more readable by abstracting away the complexities of working with the JCR API. Secondly, they improve code testability, as the models can be easily mocked in unit tests. Lastly, they promote better coding practices, such as separation of concerns, by decoupling the content structure from the business logic.

Different Types of AEM Models

There are two primary types of AEM Models: Sling Models and WCMUse Models. Sling Models are the newer and recommended approach, providing more flexibility and better integration with the Sling framework. WCMUse Models, although older and deprecated in newer versions of AEM, are still used in many existing projects.

Customizing AEM Models

While AEM provides several out-of-the-box annotations for mapping content properties, it’s possible to create custom logic in the models. This can be done by defining methods in the model and using the @PostConstruct annotation. This annotation indicates that the method should be run after the model is instantiated and all dependencies are injected.

Exporting AEM Models as JSON

AEM Models can be exported as JSON using the Sling Model Exporter. This can be useful when building headless applications, where the front end needs to consume the content as JSON. It can be achieved by annotating the model with the @Model and @Exporter annotations, and defining the properties to be included in the JSON output.

In summary, AEM Models are a powerful tool for working with AEM content in a clean, efficient, and Java-centric way. They simplify the process of accessing and manipulating content, make the code more testable, and promote better coding practices.

Back to Glossary

Axamit Blog

Get Inside Scoop on Adobe Experience Manager Updates, Trends, Best Practices
Future-Proof Your Content Authoring with a Component Content Management System
June 7, 2024

Future-Proof Your Content Authoring with a Component Content Management System

You could be leaving untapped ROI on the table with a standard CMS. But a CCMS can fix that, and we’ll explain how.

Read More
Adobe Experience Manager SEO Recipe for Global Footprint and Local Relevance
April 19, 2024

Adobe Experience Manager SEO Recipe for Global Footprint and Local Relevance

Explore how Adobe Experience Manager provides businesses with robust tools to implement SEO practices and benefit from high rankings, and stable organic traffic.

Read More
AEM Adobe Commerce Integration
April 5, 2024

Strategic AEM and Adobe Commerce Integration: Ecommerce Fueled by Content

Discover what makes the integration between AEM and Adobe Commerce a powerful key to unlocking ecommerce brand growth at scale.

Read More