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
Solved! Go to Solution.
Views
Replies
Total Likes
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
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.