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
0
votes
1 answer

AEM dialog using sling:resourceType include on the same component dialog twice

The requirement is, in a new component dialog, I need to have to tabs contains two generic CTA config , e.g: currently , my new component dialog setting as below:
sefirosu
  • 2,558
  • 7
  • 44
  • 69
0
votes
1 answer

lombok delegation pattern not returning all methods in model.json(Json Exporter) for Tabs component

I am using delegation pattern using lombok - hoping all getter method of parent super type will be exported in model.json This is the sling model I wrote for Tabs component package com.test.internal.models; import…
0
votes
1 answer

Unit test for post sling servlet aem 6.5

I have the following POST servlet that adds new node under certain resource with parameters(name and last nam) from the request: @Component( service = Servlet.class, property = { …
xMilos
  • 1,519
  • 4
  • 21
  • 36
0
votes
2 answers

how to get page path and title of child and grand child pages in aem

Can anyone help? I have a path of a root page and I want to retrieve all the child pages of root page and grandchild and grandchild of root page. My structure is like this rootPage | | |---------childPage | …
kokki
  • 1
  • 1
0
votes
2 answers

AEM get parent node from Valuemapvalue filepath in sling model

I need to get the parent folder name (String type), once a user provides a filepath in cq dialog. This is my approach: import lombok.Getter; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import…
theusual
  • 741
  • 2
  • 11
  • 24
0
votes
1 answer

Parameter to disable Sling filter in AEM

I have created a sling filter. Below is a snippet - @SlingFilter(label = "My filter", description = "Myfilter", metatype = true, generateComponent = true, generateService = true, order = 0, scope = SlingFilterScope.INCLUDE) public class…
Archit Arora
  • 2,508
  • 7
  • 43
  • 69
0
votes
0 answers

How to save array of objects into DTO class

So I have passed data in ajax as: { “name” : “Rahul”, “age” : “23”, “information” : [ { “id” : “901”, “role” : “developer” } ], “salary” : “21000”, } For this I have created two DTO classes as class…
0
votes
1 answer

AEM Mockito unit testing issue

Since i am new to Mockito and AEM model java. I have a gone through some docs and wrote my first Mockito file for AEM Model java. In my code i've not see any errors, but while running i am not getting success and can't complete the code coverage…
gopokho
  • 1
  • 1
0
votes
1 answer

How to setProperty() in node object in AEM Sling Model when doing Junit Test?

I have tried to set the property in the the node class in my unit test but was not able to do so. I would like to seek your help in sharing your knowledge on setting node property in AEM Sling MOdel for unit test if you happen to do so before. Thank…
Richard Rodjues
  • 207
  • 1
  • 6
  • 23
0
votes
0 answers

Why is Sling ignoring the "adaptable" parameter of HTL's data-sly-use?

In 2017 functionality was added to Apache Sling and HTL to allow use of the Use API with a different adaptable (such as a resource resolver, or a child resource) rather than the default backing resource or request. Feike Visser provided an example…
Spinner
  • 732
  • 1
  • 6
  • 21
0
votes
2 answers

Sling AEM / Model / Retrieve item text not value

I have an AEM site. My front-end content.xml has a select list of different color options to pick from:
West
  • 1
0
votes
1 answer

How to wrap a component with a cq:editConfig

we have a problem here with wrapping components on AEM 6.4 SP2: Let's say I want to extend the wcm core image component (v2) and create my own wrapper component to extend the feature set. The wrapper component has it's own html, and sets the…
Oliver Gebert
  • 1,166
  • 1
  • 6
  • 20
0
votes
1 answer

AEM : How to get list of registered sling models using resource type

While creating a sling model we can register it through a resource type. Is there any way through which we can get the sling model class name by providing resource type in AEM. For example : if i have a resource type /mysite/component/breadcrumb and…
user2142786
  • 1,484
  • 9
  • 41
  • 74
0
votes
2 answers

Get foundation component property in parent node sling model

I just start using Sling models, and I have an issue to retrieve a child node property in the parent model. Here is my JCR structure the image node is a from the foundation components. and my aim is to get the "filerefernce" property of the image…
k.h.t
  • 37
  • 5
0
votes
1 answer

How to export Sling Model into JSON and render it to end user?

Let's assume I have the following model: @Model(adaptables = Resource.class) public class BasicScheduleModel { @Self protected Resource resource; protected Envelope envelope; protected Status status; protected Metadata metadata; …
dzenisiy
  • 855
  • 10
  • 32