Delegation Pattern for Sling Models returns null object | Adobe Higher Education
Skip to main content
TarunKumar
Community Advisor
Community Advisor
November 12, 2021

Delegation Pattern for Sling Models returns null object

  • November 12, 2021
  • 1 risposta
  • 3794 visualizzazioni

I am trying to delegate core navigation component for my proxy navigation component. I have used below code snippet for that purpose in my sling model class.

@1961677
@2434638(type = ResourceSuperType.class)
private Navigation nav;

 

But  this type of injection is providing null object when creating model object using modelfactory. Any suggestion would be helpful.

Questo argomento è stato chiuso alle risposte.

1 risposta

TarunKumar
Community Advisor
Community Advisor
November 12, 2021

HI @asutosh_jena_ 

I have followed the same approach as mentioned the article provided by you. However, I am facing issue when I am trying to instantiate my custom model class using below line of codes:

NavigationCustomModel navigation= resource.adaptTo(NavigationCustomModel.class);

Above returns navigation as null.

MohitKumarK
Level 3
November 12, 2021

Hi @tarunkumar ,

 

In order to use sling delegation, you have to have adaptable of your sling model as SlingHttpServletRequest and resourceType property in model annotation.

 

your component should have property slingResourceSuperType pointed to right component.

 

https://aemexplained.wordpress.com/aem-guide/extending-component-using-sling-delegation/ 

 

In your case whatever the resource you are trying to adapt. It should point to a component which has this slingResourceSuperType in it.

 

if you can share sample model class how you are trying to do. I can help you. (Also component xml under apps is needed)

 

Thanks!