Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to access to an URL selector at a component level?

Avatar

Level 1

Hi,

Scenario:

(AEM 6.3.2) I'm requesting a page with the selector "test1", like this: http://localhost:4502/content/myapp/home.test1.html

This page have a parsys where I have drop a component "slider", so the component's path is: "/content/myapp/home/jcr:content/parsys/slider"

At the "slider" component level, how can I access to the "test1" selector?

I've tried different ways (SlingModel, WCMUsePojo, the "request" HTL Global Object...), but always get the same problem: the "request" I can access is the GET request of the component (GET "/content/myapp/home/jcr:content/parsys/slider.html") where the selector is not present.

I need to use that selector in a WCMUsePojo, so any HTL/Java solution will be appreciated.

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

I tried this line in one of core components. The request path you have shared is the resourcePath

selectors --> ${request.requestPathInfo.selectors}   <--

1680562_pastedImage_0.png

View solution in original post

4 Replies

Avatar

Level 10

Try this -

Set the selector in request attribute or request parameter before you can access it in WCMUsePojo's activate()

your component (HTL/jsp) can access the selector from slingrequest  something like slingHttpServletRequest.getRequestPathInfo().getSelectors() then do setAttribute(..) or setParameter(..) and get that in Pojo.

Avatar

Level 1

The problem is that when I try to access to the selector from the component's HTL, I can not see it because it's not present in the component's request.

For example, if I set this in my components HTL:

<p>Here should be a selector: -${request.requestPathInfo.selectorString}- or maybe here: -${request.requestPathInfo.selectors[0]}-, but doesn't work because the request path is: ${request.requestPathInfo.resourcePath}</p>

The output is:

<p>Here should be a selector: -- or maybe here: --, but doesn't work because the request path is: /content/myapp/home/jcr:content/parsys/slider</p>

Avatar

Correct answer by
Level 10

I tried this line in one of core components. The request path you have shared is the resourcePath

selectors --> ${request.requestPathInfo.selectors}   <--

1680562_pastedImage_0.png

Avatar

Level 1

Nevermind, just checked the same HTL in another AEM instance with the same version and it's working... I will check what is causing the wrong behavior in the old instance. Thanks!!