Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Problem with Sling Models in Adobe Experience Manager

Avatar

Former Community Member

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
Former Community Member

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

10 Replies

Avatar

Level 10

It Works perfectly well!! I tested it.

Avatar

Former Community Member

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

Avatar

Former Community Member

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

What CQ version are you using? 

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

Former Community Member

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
Former Community Member

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

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----