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
Solved! Go to Solution.
Views
Replies
Total Likes
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 .
Views
Replies
Total Likes
It Works perfectly well!! I tested it.
Views
Replies
Total Likes
on which version you have tested ? I have tried again but the POJO object is returning null when adpating from a resource
Views
Replies
Total Likes
Did you also add this into your pom.xml?
<Sling-Model-Packages>
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
What CQ version are you using?
Views
Replies
Total Likes
I just tested on AEM 6 - there was no issue:
[img]SlingModels.png[/img]
On AEM 6 - try installing the package - it works!
Views
Replies
Total Likes
smacdonald2008 wrote...
What CQ version are you using?
I am using Adobe AEM 5.6
Views
Replies
Total Likes
This is an AEM 6 community article - but we have some ppl getting it to work on 5.6.
Views
Replies
Total Likes
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 .
Views
Replies
Total Likes
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);
Views
Replies
Total Likes