Questions tagged [sling-models]

Sling Models provide the ability to use annotation driven, "pure" POJOs in Sling-based projects along with dependency injection capabilities and the ability to adapt various Sling objects OOTB.

Many Sling projects want to be able to create model objects - POJOs which are automatically mapped from Sling objects, typically resources, but also request objects. Sometimes these POJOs need OSGi services as well.

Sling Models provide these capabilities as well as basic dependency injection functionality.

The design goals include:

  • Entirely annotation driven. "Pure" POJOs.
  • Use of standard annotations where possible.
  • Pluggability
  • Ability to support resource properties (via ValueMap), SlingBindings, OSGi services, request attributes OOTB
  • Ability to adapt multiple objects - minimal required Resource and SlingHttpServletRequest
  • No need for the client to know/care that these objects are different than any other adapter factory
  • Ability to support both classes and interfaces.
  • Ability to work with existing Sling infrastructure (i.e. not require changes to other bundles).

The bundle is a part of the Apache Sling project ()

Further reading

Similar open-source solutions

  • neba.io - Spring-powered dependency injection brought to Sling
  • Slice - Guice-powered dependency injection with OOTB bindings for Sling and classes
74 questions
1
vote
2 answers

Sling model unit tests: mock currentPage in SlingHttpServletRequest

I am having some trouble testing a Sling model: the currentPage is not getting injected for some reason. My Sling model looks like this: @Model( adaptables = { SlingHttpServletRequest.class, Resource.class }, resourceType =…
Jose Berciano
  • 163
  • 2
  • 3
  • 13
1
vote
1 answer

AEM 6.3 - Multifield using Sling Model

I am trying to create a Coral UI 3 multifield and use Sling Models. Here is how the dialog looks like: Here is the code : package com.aem.sites.models; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import…
user972418
  • 817
  • 3
  • 25
  • 58
1
vote
1 answer

ResourceBundle not working in AEM 6.2

Following the documentation here, I am trying to get i18n working on my AEM 6.2 instance: Locale pageLang = currentPage.getLanguage(false); ResourceBundle resourceBundle = slingRequest.getResourceBundle(pageLang); I18n i18n = new…
Thomas
  • 6,325
  • 4
  • 30
  • 65
1
vote
2 answers

Inject another Sling model from Sling Model

2 Sling Models are given and I want to inject one of them. Is this possible with an annotation or do I need to create a PostContruct method as a workaround? Example: Model A @Model(adaptables = Resource.class) public class ModelA { …
nicolas
  • 101
  • 2
  • 9
1
vote
1 answer

AEM, Sling Models and Resource Resolver

I'm looking for an answer on this and can't find one either negatively or positively. If we get an instance of ResourceResolver through sling models injection, who is responsible for closing that resource resolver. Do we have to close it, or does…
scribe1010
  • 213
  • 3
  • 16
1
vote
1 answer

Suggestions on how to create a changewatcher on a SlingModel to enable persistence to the JCR

We are currently attempting to implement an extension to SlingModels, to allow a slingmodel to be persisted to the JCR directly. Our strategy has 2 considered starting conditions: 1. A new object that is to be persisted 2. An object that has been…
Bayani Portier
  • 660
  • 8
  • 18
1
vote
1 answer

Creating Sling Models from resource paths

I would like to instantiate a Sling Model from a JSP using a path to a resource like Within the the Sling Model, I would like to…
raro
  • 105
  • 3
  • 9
0
votes
0 answers

Junit result is not consistent always in AEM

I have the below JUNIT code. Case 1 I get Nullpointer exception error when I tried to execute it in Eclipse and I get all test cases passed when I run it in command prompt. Case 2 - I get Nullpointer exception error error sometime even when I ran…
Mario R
  • 171
  • 6
0
votes
0 answers

Unable to load JSON file using AEMContext for AEM Sling Model

I am trying to create a JUNIT for my sling model class. I am following - https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-wknd-tutorial-develop/project-archetype/unit-testing.html?lang=en. As per this doc I am using…
Mario R
  • 171
  • 6
0
votes
1 answer

How to find OOTB Page Sling model exporter class?

I want to override OOTB Page Sling model exporter class. For example - http://localhost:4502/content/we-retail/language-masters/en.model.json this makes a call to OOTB sling model exporter. I want to have similar functionalities with with changes. I…
Mario R
  • 171
  • 6
0
votes
0 answers

Need to add container id to the exporter JSON of container in AEM

I have a container component that extends the core container component..but I am not getting the container id in JSON of that component..So, I have created a custom model and injected the layout Container model used in the core container component…
0
votes
2 answers

How to make a slingshot?

enter image description here enter image description here I made this slingshot with objects in Unity3D. I know im suppose to add components but I dont know exactly which ones. The two yellows would represent as my elastics. Keep in note i have a…
alexa
  • 33
  • 1
  • 6
0
votes
1 answer

How to protect AEM pages and assets in headless architecture in AEM 6.5

I have some content in AEM and I am planning to export those content into mobile app(react) in headless way. I am using AEM content as service, sling content exporter(Jackson) to export the content. For example,…
Mario R
  • 171
  • 6
0
votes
1 answer

Pass data to sling model

Is it possible to pass a string or data that is retrieved in an Ajax call to sightly html? I have a 3rd party response in Ajax but I am trying to make the html look prettier by not using script tags. Hence I am planning to write pojos. But the call…
0
votes
1 answer

Get ResourceResolver From ResourceResolverFactory, but the ResourceResolver is not able to get Resource by given path

Given siutation like this, author click publish (activate) a page Then I have following listener to handleEvent public class ArticleContentActivationEventHandler implements EventHandler { private static final Logger LOGGER =…
sefirosu
  • 2,558
  • 7
  • 44
  • 69