#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
AJO_B2B
December 2, 2024

Adobe Journey Optimizer: Transforming B2B Customer Engagement

Explore how Adobe Journey Optimizer B2B Edition empowers businesses with personalized journeys, enhanced sales intelligence, and seamless integrations.

Read More
CJA_Examples
November 22, 2024

Customer Journey Analytics Examples and Use Cases

Discover real-world examples of Customer Journey Analytics in action and see how it can help your business improve customer engagement, retention, and conversion rates.

Read More
AEP_Article_Main
November 14, 2024

What is Adobe Experience Platform

Explore how Adobe Experience Platform connects data from multiple sources to create personalized customer experiences.

Read More