Expand my Community achievements bar.

SOLVED

Sling Models adaptables

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Correct answer by
Community Advisor

Avatar

Level 3

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.