Expand my Community achievements bar.

SOLVED

I'm encountering an error when adding my component to a page and trying to view it in publish mode

Avatar

Level 1

org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.scripting.sightly.SightlyException: Identifier com.learning.core.models.AdvancedListModel cannot be correctly instantiated by the Use API
Cannot serve request to /content/learning/test-page.html in BundledScriptServlet (/libs/sling/servlet/errorhandler/default.jsp)

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @VivekNa3 

 

Please review the following areas:

 

1. Bundle Deployment: Ensure that the class is deployed within an active OSGi bundle.

2. Sling Model Factory: Verify that the Sling Model Factory is operational.

3. Resource Matching: Confirm that the resource path and type align with the model's requirements.

 

View solution in original post

7 Replies

Avatar

Community Advisor

Hi @VivekNa3 ,

The error you're encountering suggests an issue with instantiating the AdvancedListModel in Adobe AEM using the Sightly/HTL (HTML Template Language) Use API. Here are some possible causes and solutions for this problem:

1. Ensure that the bundle containing the AdvancedListModel class is active in your AEM instance. You can check this in the Felix console (http://localhost:4502/system/console/bundles).
2. Ensure that your model class is properly annotated with @Model to indicate it is a Sling Model,
3. Double-check that the AdvancedListModel is located in the correct package and that it’s part of the active OSGi bundle in AEM.
4. Ensure that the model is being adapted from the correct resource.

MadhurMadan_0-1732399900812.png

5. Look at the detailed error logs for any additional clues that might help pinpoint the issue.


Thanks,
Madhur Madan

Avatar

Community Advisor

@VivekNa3 most of the times I have experienced a similar issue when the associated bundle is not started/satisfied.

When you see this error on the page are there any server logs that you encounter?

also, is this specific to a server instance or does the same code work on a different AEM instance?

Avatar

Community Advisor

Hi @VivekNa3 ,

 

The error you're seeing indicates that the Sling Model (com.learning.core.models.AdvancedListModel) can't be instantiated in Sightly (HTL).

Give try to below-

  1. Ensure the model is annotated with @Model(adaptables = Resource.class) and dependencies are injected properly using @SlingObject or @Inject and the bundle is active.
  2. Make sure the model has a no-argument constructor, or a constructor properly annotated with @Inject.
  3. Ensure you're using the correct data-sly-use syntax in the HTL script:
  4. Check the AEM logs for detailed error messages, especially around model instantiation.
  5. Try rebuilding the project.

These steps should help you resolve the issue.

 

Thanks

Ritesh Mittal

Avatar

Correct answer by
Community Advisor

Hi @VivekNa3 

 

Please review the following areas:

 

1. Bundle Deployment: Ensure that the class is deployed within an active OSGi bundle.

2. Sling Model Factory: Verify that the Sling Model Factory is operational.

3. Resource Matching: Confirm that the resource path and type align with the model's requirements.

 

Avatar

Community Advisor

As everyone suggested the issue is related to a problem with the instantiation of the AdvancedListModel class in your Sling application. Specifically, it indicates that the AdvancedListModel class cannot be correctly instantiated by the Sightly Use API.

Avatar

Community Advisor

Hi @VivekNa3 

Adding to the above pointer you can also check your core pom.xml and ensure the export declaration is proper.

<Export-Package> your packagename;version=1.0.0 </Export-Package>

also add some loggers in your model class and see if the invocation is happening and check the class in system console components