@SlingObject SlingHttpServletReponse is returning null value | Community
Skip to main content
Nitiks25
Level 2
October 4, 2017
Solved

@SlingObject SlingHttpServletReponse is returning null value

  • October 4, 2017
  • 4 replies
  • 2894 views

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.
Best answer by smacdonald2008

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

smacdonald2008
Level 10
October 4, 2017

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.

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 4, 2017

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.")

Nitiks25
Nitiks25Author
Level 2
October 9, 2017

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?

Nitiks25
Nitiks25Author
Level 2
October 9, 2017

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