Expand my Community achievements bar.

SOLVED

Best way to get a request object from a pageContext object while using Taghandlers.

Avatar

Level 4

Which is the correct way to get a slingRequest from a pageContext object in Tag Handlers. Will it give same result always?

        SlingHttpServletRequest slingRequest1 = TagUtil.getRequest(pageContext);
        SlingHttpServletRequest slingRequest2 = (SlingHttpServletRequest) pageContext.getRequest();
        SlingHttpServletRequest slingRequest3 = (SlingHttpServletRequest)pageContext.getAttribute("slingRequest");

1 Accepted Solution

Avatar

Correct answer by
Level 10

Feike has a blog that shows this:

http://blogs.adobe.com/experiencedelivers/experience-management/my-favourite-cq5-utils-htmlcq_ck1416...

TagUtil

http://​dev​.day​.com/​d​o​c​s​/​e​n​/​c​q​/​c​u​r​r​e​n​t​/​j​a​v​a​d​o​c​/​o​r​g​/​a​p​a​c​h​e​/​s...

// gets the SlingRequest/SlingResponse when you are cre­at­ing cus­tom tags

Page­Con­text page­Con­text = (Page­Con­text) getJspContext();

SlingHttpServle­tRe­quest slin­gRe­quest = TagUtil.getRequest(pageContext);

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Feike has a blog that shows this:

http://blogs.adobe.com/experiencedelivers/experience-management/my-favourite-cq5-utils-htmlcq_ck1416...

TagUtil

http://​dev​.day​.com/​d​o​c​s​/​e​n​/​c​q​/​c​u​r​r​e​n​t​/​j​a​v​a​d​o​c​/​o​r​g​/​a​p​a​c​h​e​/​s...

// gets the SlingRequest/SlingResponse when you are cre­at­ing cus­tom tags

Page­Con­text page­Con­text = (Page­Con­text) getJspContext();

SlingHttpServle­tRe­quest slin­gRe­quest = TagUtil.getRequest(pageContext);

Avatar

Level 4

Thanks Scott for the quick response.