Sling Models adaptables | Community
Skip to main content
Level 3
September 7, 2022
Solved

Sling Models adaptables

  • September 7, 2022
  • 3 replies
  • 1429 views

Hi All,

 

Could you please please explain about the adaptables in sling models when to go for Resource and when to go for SlingHttpServletRequest what is the  use cases

 

@ Model(Adaptables=Resource.class)

- what will exactly happen when we adapt Resource

@ Model(Adaptables=SlingHttpServletRequest.class)

what will exactly happen when we adaptSlingHttpServletRequest

 

Please explain by use case if you have

 

Thank you

3 replies

arunpatidar
Community Advisor
Community Advisor
September 7, 2022

Hi,

Please check usage of various annotations which supported only with either Resources or SlingHttpServletRequest

https://sling.apache.org/documentation/bundles/models.html#injector-specific-annotations-1 

https://sling.apache.org/documentation/bundles/models.html#available-injectors 

 

 

Arun Patidar
Level 2
May 13, 2023

we use resource.class when the class itself is a resource and SlingHttpServletRequest.class is used for getting request objects

Resource is the most commonly used adaptable in Sling Models. It represents a resource in the JCR repository, such as a node or a property. You would typically use Resource as an adaptable if you want to access and manipulate the properties and child nodes of a specific JCR resource.

On the other hand, SlingHttpServletRequest is another adaptable in Sling Models that represents an HTTP request to the Sling framework. You would typically use SlingHttpServletRequest as an adaptable if you want to access the request parameters, headers, and other metadata associated with an HTTP request.