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

Delegation Pattern for Sling Models returns null object

  • November 12, 2021
  • 1 reply
  • 3814 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

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.

TarunKumar
Community Advisor
Community Advisor
November 16, 2021

Hi @tarunkumar ,

As per your sling model, you are extending for navigation component. But you are trying to adapt a page as your navigation model. May be thats the reason you are getting null. Try to adapt a resource which is of type (myproject/components/content/navigation).

Remember this navigation component should extend (sling:resourceSuperType) as core navigation component.

Thanks!


Hi @mohitkumark 

Thanks for your reply. I have tried adapting to resource "myproject/components/content/navigation" as well but this also doesn't serve the purpose and my navigation object appear as null.

Also attached is the screen print of my navigation component which is extending the core navigation component.