Expand my Community achievements bar.

SOLVED

Retrieving the 'SlingHttpServletRequest request' from a parent node.

Avatar

Level 3

Hi Community!

For some reasons I need to retrieve the 'SlingHttpServletRequest request' from a parent node and I'm not be able to do it, I have already the request from the actual node but I'm passing on HTL an wcmmode='disabled' fixed value, this is why I'm going to need the parent request, sample code here:

          Resource resource = request.getResource();       

          Resource parent = resource.getParent();

          SlingHttpServletRequest requestParent = parent.adaptTo(SlingHttpServletRequest.class);

This is how I'm trying on the constructor on my class, but always I retrieve null as requestParent value.

I'll appreciate any suggestions on this, thanks in advance.

AEM6.2

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Kenny

     I am afraid , I am still not clear about your use case. Could you please try to explain your use case or requirement around the component little more clearly

   To answer your this question, (even though i didn't understand what your are trying to do here ) , you can always get a SlingHttpServletRequest object in your model using the code snippet I have mentioned in the below answer Re: Sightly question: how to adapt a class with a path

@Model(adaptables = SlingHttpServletRequest.class)

    Once you have the request you can always adapt a resource and play around

BUT, What i see in your code is you already have a request object ,

Resource resource = request.getResource();   

     Could you tell me what exactly are you trying to implement by fetching another request object (which doesn't make sense since you already have one . ) , when you can do almost everything using the Resource API .

PS:- All my above answers are direct to your question. Still I am not sure about your requirement . And as smacdonald2008 said, I don't think this is a correct approach.

View solution in original post

21 Replies

Avatar

Level 7

From what I think:

- Authorable options for a particular component should be kept in its own dialog. As you are using same component(which may not be used on its own), it should still have it own dialog.. Its component group can be hidden and these can be added statically in parent component.

- If you are still keen on storing it in parent dialog, you can fetch the values from parent resource directly without adapting it to request object. You already have the child(social share object) and you get parent of it and then fetch whatever values you need from there.