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
Solved! Go to Solution.
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
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 for posting this. I will update the article we have on Sling Models to include this great information.
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>
Views
Replies
Total Likes
Is your java package structure right ? TouchUIMultiField.core.models.StudentsModel ?
See if this helps Java Use-API: No use provider could resolve identifier
Views
Replies
Total Likes
It is solved now the issue is with caps in package name
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Yes, this approach also works. Same we are using in our case.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies