Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

@SlingObject SlingHttpServletReponse is returning null value

Avatar

Level 3

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?

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

4 Replies

Avatar

Level 10

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.

Avatar

Correct answer by
Level 10

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

Avatar

Level 3

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?

Avatar

Level 3

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