Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Problem - Sling Model not getting invoked

Avatar

Community Advisor

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

1319067_pastedImage_0.png

But I added one of the model in the below package

1319078_pastedImage_3.png

     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

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

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

1319067_pastedImage_0.png

But I added one of the model in the below package

1319078_pastedImage_3.png

     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

Avatar

Level 10

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

Avatar

Level 3

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

1576050_pastedImage_1.png

1576051_pastedImage_0.png

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>

Avatar

Community Advisor

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

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

Avatar

Level 3

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

Avatar

Level 1

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

Avatar

Level 4

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