Problem with Sling Models in Adobe Experience Manager | Community
Skip to main content
October 16, 2015
Solved

Problem with Sling Models in Adobe Experience Manager

  • October 16, 2015
  • 10 replies
  • 2812 views

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

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

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 .

10 replies

Ratna_Kumar
New Participant
October 16, 2015

It Works perfectly well!! I tested it.

October 16, 2015

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

Feike_Visser1
Employee
October 16, 2015

Did you also add this into your pom.xml?

<Sling-Model-Packages>

https://sling.apache.org/documentation/bundles/models.html

October 16, 2015

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.

smacdonald2008
New Participant
October 16, 2015

What CQ version are you using? 

smacdonald2008
New Participant
October 16, 2015

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

[img]SlingModels.png[/img]

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

October 16, 2015

smacdonald2008 wrote...

What CQ version are you using? 

 


I am using Adobe AEM 5.6

smacdonald2008
New Participant
October 16, 2015

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

Accepted solution
October 16, 2015

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 .

Feike_Visser1
Employee
October 16, 2015

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);