@SlingObject SlingHttpServletReponse is returning null value | Community
Skip to main content
Nitiks25
Level 2
Oct 4, 2017 2:50 PM UTC
Solved

@SlingObject SlingHttpServletReponse is returning null value

Hi All, I have a sling model and I am using @SlingObject SlingHttpServletReponse reponse to get a reference to the response object

same works fine in author but in publisher the response object is null

Any thoughts on why this might be?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 4, 2017 3:32 PM UTC

You can also access that object in HTL by using WCMUSEPOJO.

You can easily get it by invoking the getRequest method"

WCMUsePojo ("The CQ5 Quickstart and Web Application.")

4 replies

Nitiks25
Nitiks25Author
Level 2
Oct 9, 2017 1:40 PM UTC

Or should be using @Inject @Via(SlingHttpServletRequest.class) SlingHttpServletResponse response

Translate
Nitiks25
Nitiks25Author
Level 2
Oct 9, 2017 7:58 AM UTC

Thanks SmacDonald. I'm using Resource as the adaptable. From the documentation, I understand that response object may not be available if resource is used as the adaptable. Workaround would be to use @Via to get the response object from request adaptable. And @SlingObject is supposed to be a replacement of @Via so @SlingObject should be able to inject the response object too even if the adaptable is Resource. Am I right in my understanding?

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 4, 2017 3:32 PM UTC

You can also access that object in HTL by using WCMUSEPOJO.

You can easily get it by invoking the getRequest method"

WCMUsePojo ("The CQ5 Quickstart and Web Application.")

Translate
smacdonald2008
Level 10
Oct 4, 2017 3:28 PM UTC

If it works fine in Author - but not in Publisher - this means there is something missing on Publisher that is present in the Author instance.

Translate