Purpose of SlingHttpServletRequest as adaptables in Sling model | Community
Skip to main content
koushikd3750389
New Participant
Dec 28, 2018 11:51 AM UTC
Solved

Purpose of SlingHttpServletRequest as adaptables in Sling model

I am not able to understand when to use 'SlingHttpServletRequest' and 'Resource' as adaptables in sling model. Can someone please clarify my doubts ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
rampai
rampaiAccepted solution
Level 1
Jan 4, 2019 9:50 AM UTC

When you want to interact with something in OSGi using a servlet or obtain something from the incoming request, you can go for SlingHttpServletRequest. When the interaction is purely with AEM resource you can go for Resource.

As mentioned in the documentation , using SlingHttpServletRequest, you can still get the resource something along the lines of request.getResource():

@Model(adaptables=SlingHttpServletRequest.class) public interface MyModel { 

// will return request.getResource().getValueMap().get("propertyName", String.class) @Inject @Via("resource") String getPropertyName(); }

1 reply

rampai
rampaiAccepted solution
Level 1
Jan 4, 2019 9:50 AM UTC

When you want to interact with something in OSGi using a servlet or obtain something from the incoming request, you can go for SlingHttpServletRequest. When the interaction is purely with AEM resource you can go for Resource.

As mentioned in the documentation , using SlingHttpServletRequest, you can still get the resource something along the lines of request.getResource():

@Model(adaptables=SlingHttpServletRequest.class) public interface MyModel { 

// will return request.getResource().getValueMap().get("propertyName", String.class) @Inject @Via("resource") String getPropertyName(); }

Translate