Problem - Sling Model not getting invoked | Community
Skip to main content
VeenaVikraman
Community Advisor
Community Advisor
October 6, 2017
Solved

Problem - Sling Model not getting invoked

  • October 6, 2017
  • 6 replies
  • 11059 views

The sling models which were created was not getting invoked . A similar question annotations - AEM Osgi Sling Model @PostConstruct never called - Stack Overflow .

Adding this here so that in future anyone facing the same issue should get the answer immediately

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 VeenaVikraman

Solution :-

1) First go to http://localhost:4502/system/console/status-adapters  and check if your model is registered correctly

           - if the model is not showing up, then please go and check the <Sling-Model-Packages> property of the maven-bundle-plugin.

For eg:-

  In my project I had the Sling-Model-Packages declared as below

But I added one of the model in the below package

     So if you see , my sling-model-packages will be referenced only from com.xxx.aem.website.core , but here my model was added to com.xxx.aem.website.models which will never get referenced

Thanks to https://stackoverflow.com/a/41909690/8671041

6 replies

VeenaVikraman
Community Advisor
VeenaVikramanCommunity AdvisorAuthorAccepted solution
Community Advisor
October 6, 2017

Solution :-

1) First go to http://localhost:4502/system/console/status-adapters  and check if your model is registered correctly

           - if the model is not showing up, then please go and check the <Sling-Model-Packages> property of the maven-bundle-plugin.

For eg:-

  In my project I had the Sling-Model-Packages declared as below

But I added one of the model in the below package

     So if you see , my sling-model-packages will be referenced only from com.xxx.aem.website.core , but here my model was added to com.xxx.aem.website.models which will never get referenced

Thanks to https://stackoverflow.com/a/41909690/8671041

smacdonald2008
Level 10
October 6, 2017

Thanks for posting this. I will update the article we have on Sling Models to include this great information.

Prabhat_Jain
Level 2
September 21, 2018

My sling model is registered but then also I am getting error

HTL Code:

<div>

    <b>Students Information</b>

    <br><br>

    <div data-sly-use.studentModel="TouchUIMultiField.core.models.StudentsModel" data-sly-unwrap>

        <div data-sly-test="${!studentModel || wcmmode.edit}">

            Add students using component dialog

        </div>

        <div data-sly-test="${studentModel.studentList}">

            <div data-sly-list.student="${studentModel.studentList}">

                <div>

                    <div>Student Name: ${student.studentName}</div>

                    <div>Student Roll Number: ${student.studentRollNumber}</div>

                    <br>

                    <div data-sly-list.subject="${student.subjectList}" style="margin-left:40px">

                        <div>Subject No.: ${subjectList.count}</b></div>

                        <div>Name: ${subject.subjectName}</b></div>

                        <div>Grade: ${subject.subjectGrade}</div>

                        <div>Marks: ${subject.subjectMarks}</div>

                        <div>Teacher: ${subject.subjectTeacher}</div>

                        <br>

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>

VeenaVikraman
Community Advisor
Community Advisor
September 21, 2018

Is your java package structure right ? TouchUIMultiField.core.models.StudentsModel ?

See if this helps Java Use-API: No use provider could resolve identifier

Prabhat_Jain
Level 2
September 25, 2018

It is solved now the issue is with caps in package name

June 7, 2021

Another way to expose your sling models is by creating the `package-info.java file in your package where the sling model exists.


For example, if your sling model is inside com.aem.core.models.components  then create the package-info.java file like this-

@Version("1.0")
package com.aem.core.models.components;
import org.osgi.annotation.versioning.Version; 

 

This will enable the bnd-maven-plugin to pick this sling model up.

 

https://github.com/adobe/aem-project-archetype/issues/221

Level 3
July 7, 2022

Yes, this approach also works. Same we are using in our case.