Sling Modles - Specifying an Alternate Adapter Class | Community
Skip to main content
Dinu_Arya
Level 6
June 15, 2016
Solved

Sling Modles - Specifying an Alternate Adapter Class

  • June 15, 2016
  • 5 replies
  • 1251 views

Hi Team,

I tried the below code in sling models but I got error for declaring adapters -

@Model(adaptables = Resource.class, adapters = MyModel.class)
public class MySlingModel {
}

I'm using the below dependencies -

    <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.models.api</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>

Earlier I used for the version 1.0.0. But it is not working. I'm unable to use adapters.

Can you pls help me in this?

Thanks,

AryA.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AnkurAhlawat-1

You have used @Model incorrectly.

There is no way to create a Sling Model from more than one adaptable, Your class can adapt to multiple means it can adapt to different classes but at one point of time only one.

Read more about How to use Sling Model with Sightly in AEM

regards,

Ankur Ahlawat

AEM CQ5 Tutorials

5 replies

smacdonald2008
Level 10
June 15, 2016

What version of AEM are you using? 

smacdonald2008
Level 10
June 15, 2016

We are going to release a new AEM 6.2 SLing Model Article. I will post soon. 

kautuk_sahni
Community Manager
Community Manager
June 16, 2016

Hi 

Please refer to :- https://helpx.adobe.com/experience-manager/using/sling_models.html

//

Adding following dependency to the pom.xml help overcoming this problem:

<dependency>

    <groupId>org.apache.geronimo.specs</groupId>

    <artifactId>geronimo-atinject_1.0_spec</artifactId>

    <version>1.0</version> <scope>provided</scope>

</dependency>

Reference :- Go to depfinder:- http://localhost:4502/system/console/depfinder  [to find out dependency]

Please let me know, what exactly is the error coming?

PS:- Please add the dependency mentioned. Even the article Link mentioned by me is missing with this dependency, so add it and run it.

Thanks and Regards

Kautuk Sahni 

Kautuk Sahni
kautuk_sahni
Community Manager
Community Manager
June 28, 2016

smacdonald2008 wrote...

We are going to release a new AEM 6.2 SLing Model Article. I will post soon. 

 

Article Released:- https://helpx.adobe.com/experience-manager/using/slingmodel_62.html

~kautuk

Kautuk Sahni
AnkurAhlawat-1
AnkurAhlawat-1Accepted solution
Level 6
June 29, 2016

You have used @Model incorrectly.

There is no way to create a Sling Model from more than one adaptable, Your class can adapt to multiple means it can adapt to different classes but at one point of time only one.

Read more about How to use Sling Model with Sightly in AEM

regards,

Ankur Ahlawat

AEM CQ5 Tutorials