#Adobe Experience Manager

What Are Models in AEM

Sommaire

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.

Retour au glossaire

Blog d'Axamit

Obtenez les dernières informations sur Adobe Experience Manager Mises à jour, tendances, meilleures pratiques
What is RT-CDP
février 3, 2025

Qu’est-ce qu’Adobe Real-Time Customer Data Platform

Découvrez les avantages et les défis d'Adobe Real-Time CDP. Du traitement des données en temps réel à la génération de contenu dynamique, découvrez comment cet outil puissant peut aider les entreprises à offrir des expériences client personnalisées — et où il pourrait présenter des lacunes.

Lire la suite
janvier 23, 2025

Revitaliser l’engagement client avec la CDP pour le commerce électronique et le commerce de détail

Découvrez Adobe Real-Time CDP pour les industries du commerce de détail et de l'e-commerce. Apprenez à personnaliser les parcours clients, à renforcer l'engagement et à garantir la conformité.

Lire la suite
AJO_B2B
décembre 2, 2024

Adobe Journey Optimizer : Transformer l’engagement client B2B

Découvrez comment Adobe Journey Optimizer B2B Edition permet aux entreprises de bénéficier de parcours personnalisés, d'une intelligence commerciale améliorée et d'intégrations fluides.

Lire la suite