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
2
votes
0 answers

Eclipse apache sling -- internal error occured while eclipse trying to connect to external sling server

I was trying to setup the Eclipse development environment for Apache Sling by following the instructions at https://sling.apache.org/documentation/development/ide-tooling.html I got an error while trying to connect to an external Apache Sling…
George Wang
  • 765
  • 2
  • 13
  • 28
2
votes
3 answers

Sling deploy content and bundle with maven

Iam searching for a maven based solution to deploy apache sling bundle and content (including jsp/html, etc files) on my sling standalone server. I stated this private project to learn about sightly and sling models without using AEM. It is my…
Tim
  • 287
  • 1
  • 13
1
vote
1 answer

Remove empty json field in Component Expoter

How to exclude Json tab field when it has no value being authored in component dialog field (Sling model)? dialog a (authored value) tab b (not authored) tab json response with model.json of experience fragment "Component" : { "a":{ …
1
vote
1 answer

service returning null when calling from another model

I have created an replication service to publish a page and its assets using replicator...but whenever I am trying to call this service to a util class,it is returning null.Can anyone help me with why I am getting null and how to get the instance of…
1
vote
0 answers

How to return current Page and fetch value by using @Via("resource")?

@Model(adaptables = SlingHttpServletRequest.class , defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class Solution { @ScriptVariable Page currentPage; @Inject @Via("resource") @Default(values="Heading of…
Questioner
  • 31
  • 3
1
vote
3 answers

How to display a json response mapped pojo in sightly

I have a sling servlet that invokes a 3rd party api and fetches a json response. I have mapped the json response to a pojo class using Jackson. I now have to display this dynamically fetched and mapped response in sightly. How do i do that? I am…
1
vote
2 answers

AEM slingmodels - why do we need unused adaptables in each model? Why need both Resource & SlingHTTPRequest?

I am working on a project where every model has this line: @Model(adaptables = { SlingHttpServletRequest.class,Resource.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) In my understanding: If Resource or SlingHTTPRequest is…
theusual
  • 741
  • 2
  • 11
  • 24
1
vote
1 answer

Access AEM component data as JSON within HTL (Sightly)

I have created a component the fields of which have been mapped to a sling model. To get the data of the sling as JSON I have enabled Sling exporter as shown in the code below - @Model(adaptables = { Resource.class }, defaultInjectionStrategy =…
Archit Arora
  • 2,508
  • 7
  • 43
  • 69
1
vote
0 answers

Do not include a component sling exporter data in page sling exporter - AEM

We have developed a sling exporter for our Page component which exports all the data for the child components as well (using the ContainerExporter method getExportedItems). I don't want to include some components in the data, so, for that I have…
ankur_rajput
  • 145
  • 2
  • 11
1
vote
0 answers

How to fetch current page in sling model

I created some pages with hierarchy like Home page Men Watches Smart watch Analog watch Shoes Sports shoes Formal shoes Women Watches Smart watch Analog watch Shoes Sports shoes Formal shoes How can I fetch current page, that…
1
vote
1 answer

What is the use of @Model(adaptables = Resource.class) in Sling models?

What difference would it make if I write @Model(adaptables=SlingHttpServlet.class)?
user3763246
  • 13
  • 1
  • 5
1
vote
1 answer

Error during include of component : xxx cannot be resolved to a type

I developed a class DateFormatter in core bundle following blog . and get my date value in header page :
Xie Kevin
  • 31
  • 1
  • 7
1
vote
1 answer

Sling models vs WCMUSEPOJO

I need an understanding of what wcmusepojo and sling models mean? I mean I've read that these implementations are to bring together your component and the back-end implementation but what exactly is done in these (wcmusepojo and sling models) vs…
Vishal--JAVA--CQ
  • 188
  • 1
  • 2
  • 18
1
vote
2 answers

Unable to adapt model class into SlingHttpServletRequest

I am trying to inject resources in my model class. Problem I face when I use annotation @Model(adaptables = { SlingHttpServletRequest.class, Resource.class }) I am getting objects as null, whereas with only Resource.Class I am getting the objects…
Vivek Dhiman
  • 1,967
  • 6
  • 46
  • 82
1
vote
4 answers

How to get page properties using sling model in aem 6.3?

I am trying to get page properties using Sling Models in AEM 6.3 but always I am getting null. resultsRootPath = getCurrentPage().getProperties().get("ResultsRootPath", String.class); Path of…
Ram
  • 27
  • 1
  • 1
  • 3