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

How to share data between a page and a component in AEM 6.2?

Is there a way how I can call the same instance of a model within HTL using the same data? I want to create an object within the model of a page, let's say a String object, and then use it in the model of a component. To create the bean (or model…
Alex-2017a
  • 11
  • 2
0
votes
2 answers

How to call Sling Model Method with input parameter AEM

I am having a scenario in which i want to call a sling model with input parameter. For this i have a code like this
But I want to call a method in sling model…
Shivani Garg
  • 735
  • 13
  • 37
0
votes
1 answer

SlingModels: How to build the form component from foundation (inject PageContext?)

The foundation component from AEM are just plain JSP without much logic in any java bean. I now try to convert the form components java logic into Sling Models. But the start component again is not easy as there are two things to be done (copied…
Thomas
  • 6,325
  • 4
  • 30
  • 65
0
votes
3 answers

SlingModels: Injecting other Model from SlingHttpServletRequest

One reason for my other question is the following use case: I want to create a TextImageModel which uses my ImageModel as an injected property and extends my TextModel: @Model(adaptables = {SlingHttpServletRequest.class}) public class TextImageModel…
Thomas
  • 6,325
  • 4
  • 30
  • 65
0
votes
1 answer

what is the difference(benifits) between using sling model and Model creating using WCMUSE?

What is the difference between creating @Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class MyModel { } and public class MyModel extends WCMUsePojo { }
Riding Cave
  • 1,029
  • 1
  • 15
  • 32
0
votes
1 answer

how to use two different sling models(parent sling model in child components html) in sightly?

I have Parent Component and child components. I am including child components(3 types of html based on type) in parent component(html) using data-sly-resource in sightly. For type 3 child component I need to render Parent component's data(i have…
Riding Cave
  • 1,029
  • 1
  • 15
  • 32
0
votes
1 answer

Problems Testing Sling Model with Custom Injectors

I've been doing some work with sling models for a project and in the process created a couple of custom injectors. Everything seems to work great when implemented (used in AEM). However, when I'm testing the custom injectors are not getting…
Brodie
  • 8,399
  • 8
  • 35
  • 55
0
votes
1 answer

How to get LanguageManager class in SlingModels?

I am declaring LanguageManager class but not getting how to instantiate it. ResourceResolver res = resource.getResourceResolver(); **LanguageManager languagemanager= null;** final PageManager pageManager =…
Shruti h
  • 37
  • 8
0
votes
0 answers

Resource Resolver being returned as null via Sling Models Annotation

Resource Resolver is being returned as null while injecting through sling models , let me know if anything i am missing : I tried with : @Model(adaptables = Resource.class) public class Navigation { @Inject @Source("sling-object") private…
user3837000
  • 121
  • 3
  • 12
-1
votes
1 answer

AEM: passing properties to sightly component from sling model inside HTML

We have a requirement wherein we need to create a template dynamically using the sling model response. The challenge here is we have got some common components that we want to use for building up our template. Is there a way that I can set the…
-1
votes
2 answers

How to get design dialog properties in Sling model?

I have a design dialog where the values are getting stored in etc/design//. But now how should i read these property in Sling model?
Ishita Gandhi
  • 21
  • 1
  • 2
  • 6
-1
votes
2 answers

Resource Resolver returned as null via sling models

Resource Resolver is being returned as null while injecting through sling models, let me know if anything I am missing : I tried with : @Model(adaptables = Resource.class) public class Navigation { @Inject @Source("sling-object") private…
user3837000
  • 121
  • 3
  • 12
-2
votes
1 answer

What is the significance of declaring a sling model as (adaptables = Resource.class)

In Sling Model, the model class is annotated as @Model(adaptables = Resource.class) What is the significance of passing the param as adaptables = Resource.class. What if I don't pass any parameter. What all parameter @Model accepts.
-3
votes
1 answer

What is the use of @postconstructor in AEM SlingModel concept?

When can I use @postconstructor when I'm using in the SlingModel? @Model(adaptables=SlingHttpServletRequest.class) public class MyModelTest { @Inject private PrintWriter out; @Inject @Named("log") private Logger logger; …
Sara_123
  • 13
  • 2
1 2 3 4
5