Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Problem with Sling Models in Adobe Experience Manager

Avatar

Level 3

I am working on below community article related to Sling Models.  I follwed the steps given there but I am not able to map my Java Model/POJO. 

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

I have added below dependency to my pom.xml  and I also added below tag inside maven bundle plugin to ensure the model/POJO will be adaptable

My POJO/Model class UserInfo.java is located  inside "com.ritwik.poc.sling.models" package.

<Sling-Model-Packages>com.ritwik.poc.sling.models</Sling-Model-Packages>

 <dependency>

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

But I am getting null userInfo object when adapting from a sling resource .

 Resource resource = resourceResolver.getResource("/content/testsling/slingmodel"); 
 com.ritwik.poc.sling.models.UserInfo userInfo = resource.adaptTo(com.ritwik.poc.sling.models.UserInfo.class);

I am able to access resource properties using valuemap api. Kindly help me in fixing the issue.

Thanks

Abhilash Sathi

1 Accepted Solution

Avatar

Correct answer by
Level 3

smacdonald2008 wrote...

This is an AEM 6 community article - but we have some ppl getting it to work on 5.6.

 


Thanks Scott. I thought sling models are part of AEM 5.6 . After looking at your comment I have tried to install two bundles related to Sling Models manually and then its working fine.

org.apache.sling.models.api » 1.0.0

 org.apache.sling.models.impl » 1.0.0

I have downloaded above two bundles from maven respository and installed using AEM felix console . Then everything went fine. I would like to thank all active participants in AEM help forums since these are really helpful and informative for all AEM user especially beginers .

View solution in original post

0 Replies

Avatar

Community Advisor

It Works perfectly well!! I tested it.

Avatar

Level 3

on which version you have tested ? I have tried again but the POJO object is returning null when adpating from a resource

Avatar

Level 3

I have added that Tag in POM. Actual problem is Sling model related bundles are not part of my CQ installation (5.6) . I have downloaded couple bundle and after installing those two everything worked fine. Thanks for you support.

Avatar

Level 10

I just tested on AEM 6 - there was no issue: 

[img]SlingModels.png[/img]

On AEM 6 - try installing the package - it works! 

Avatar

Level 3

smacdonald2008 wrote...

What CQ version are you using? 

 


I am using Adobe AEM 5.6

Avatar

Level 10

This is an AEM 6 community article - but we have some ppl getting it to work on 5.6.

Avatar

Correct answer by
Level 3

smacdonald2008 wrote...

This is an AEM 6 community article - but we have some ppl getting it to work on 5.6.

 


Thanks Scott. I thought sling models are part of AEM 5.6 . After looking at your comment I have tried to install two bundles related to Sling Models manually and then its working fine.

org.apache.sling.models.api » 1.0.0

 org.apache.sling.models.impl » 1.0.0

I have downloaded above two bundles from maven respository and installed using AEM felix console . Then everything went fine. I would like to thank all active participants in AEM help forums since these are really helpful and informative for all AEM user especially beginers .

Avatar

Employee

You have this code:

com.ritwik.poc.sling.models.UserInfo userInfo = resource.adaptTo(com.ritwik.poc.sling.models.UserInfo.class);

to me it should be like:

com.ritwik.poc.sling.models.UserInfo userInfo = resource.adaptTo(com.ritwik.poc.sling.models.UserInfo);