Skip to main content
Level 5
July 26, 2017
Répondu

Sightly question: how to adapt a class with a path

In java code, I can do this:

Resource articleResource = resourceResolver.getResource("/somepath/for/article");
  Article article = articleResource.adaptTo(Article.class);

Can Sightly do the same? and how?

In AEM 6.3 with sling models.

Thanks.

Ce sujet a été fermé aux réponses.
Meilleure réponse par VeenaVikraman

Probably my answer would be yes. Try the below code

  Let me know if it doesn't work

Thanks

Veena

13 commentaires

VeenaVikraman
Community Advisor
Community Advisor
July 26, 2017

I think @Model(adaptables = Resource.class) and @Model(adaptables = SlingHttpServletRequest.class) both should work

BigT168Auteur
Level 5
July 26, 2017

I tried, only adaptables = Resource.class works. Other one returns null after articleResource.adaptTo(Article.class);

VeenaVikraman
Community Advisor
Community Advisor
July 26, 2017

okay cool. I don't find an option to edit the answer after it is marked correct.