top of page
Writer's pictureHeena

Adaptables parameter in Sling Model | AEM

Updated: May 2


Confused about when to pass what class in adaptables parameter to the @Model annotation in an AEM Sling Model?


@Model annotation

When defining a Sling Model class, the adaptables parameter to the @Model annotation is mostly determined by the injectors being used in it.



What class you passed totally depends on what you want out of the model. If you want to fetch values from for example the authored values, which is in turn a resource, you will pass Resource.class. Whereas, if you want to fetch request based values, you will pass SlingHttpServletRequest.class to adaptables.



For example, if the Sling Model only uses @ValueMapValue, then adaptable will be set to Resource.class. Whereas if it uses for eg. @ScriptVariable/@RequestAttribute then adaptable should be SlingHttpServletRequest.class.


Also, you can pass one or more values to adaptables parameter as follows:

How to pass one or more values to adaptables parameter



That's all for today! If you've found this blog post informative or helpful, I’d greatly appreciate it if you could give it a like. It keeps me motivated 💛


Enjoying my ad-free blog? Support by buying me a coffee! I've kept this space ad-free, sponsoring it myself to maintain its purity. Your contribution would help keep the site afloat and ensure quality content. Thanks for being part of this ad-free community.

292 views

Related Posts

See All

Comments


bottom of page