I'm encountering an error when adding my component to a page and trying to view it in publish mode | Community
Skip to main content
November 23, 2024
Solved

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

  • November 23, 2024
  • 8 replies
  • 1852 views

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)

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 Pallavi_Shukla_

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.

 

8 replies

Madhur-Madan
Community Advisor
Community Advisor
November 23, 2024

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.

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


Thanks,
Madhur Madan

Tethich
Community Advisor
Community Advisor
November 24, 2024

Check if you use optional injection strategy as well in your model : https://sling.apache.org/documentation/bundles/models.html#optional-and-required-1

Preetpal_Bindra
Community Advisor
Community Advisor
November 25, 2024

@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?

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
November 25, 2024

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

Pallavi_Shukla_
Community Advisor
Pallavi_Shukla_Community AdvisorAccepted solution
Community Advisor
November 25, 2024

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.

 

Ravi_Pampana
Community Advisor
Community Advisor
November 25, 2024

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.

sherinregi-1
Community Advisor
Community Advisor
November 26, 2024

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

 

joerghoh
Adobe Employee
Adobe Employee
December 1, 2024

the exception trace will contain more information what exactly failed, and the error messages are normally quite helpful.