register sling model exporter at cq:Page with custom selector | Community
Skip to main content
cwalter-1
Level 2
May 27, 2020
Solved

register sling model exporter at cq:Page with custom selector

  • May 27, 2020
  • 2 replies
  • 6519 views

We are currently working with a headless approach and I'm trying to estimate pros & cons of having more selectors in addition to 'model' at the cq:Page component. After digging through the request log and basically discovering what @joerghoh  also mentioned here: https://cqdump.wordpress.com/2019/01/07/how-does-sling-resolve-an-aem-page-to-the-correct-resource-type/  some special magic included within the cq:Page component redirects requests with special selector 'model' to the page-content where the sling-model-exporter ist registered.

It is easily possible to register sling-model-exporters to component-nodes if they have a proper sling:resourceType set but would it make sense to have this option on the page level too? Any dispatcher or security related issues maybe?

 

for instance

 

/content/somepage.model.json works

/content/somepage/jcr:content.customselector.json works

/content/somepage.customselector.json doesn't ?

 

 

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 joerghoh

Hi Christoph,

If I understand you correctly, you would just start registering customer exporters as selectors selectors to the cq/Page resourcetype.

Technically I don't see a problem with that, but just be aware, that I can execute this exporter on pages where it shouldn't work. That means you need to write some code to ensure that this exporter is just executed on the right "type" of page, and not on any page. If you register that SME directly to the correct resource type, Sling does that for you.

2 replies

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
May 27, 2020

Hi Christoph,

If I understand you correctly, you would just start registering customer exporters as selectors selectors to the cq/Page resourcetype.

Technically I don't see a problem with that, but just be aware, that I can execute this exporter on pages where it shouldn't work. That means you need to write some code to ensure that this exporter is just executed on the right "type" of page, and not on any page. If you register that SME directly to the correct resource type, Sling does that for you.

cwalter-1
cwalter-1Author
Level 2
May 28, 2020
But a model is tied to a specific resourcetype?! The 'model' selector only forwards the request to the sling-model if there is a model registered at the resourcetype of the pages content-resource.
arunpatidar
Community Advisor
Community Advisor
May 27, 2020

Hi,

sling models work for page as well, if you do like /content/weretails/en.model.json

 

But if you looking for something custom, then it should be validated in terms of performance and error handling.

I tried to created similar just for fun - https://aemlab.blogspot.com/2019/07/get-json-response-of-aem-page.html

 

Arun Patidar
cwalter-1
cwalter-1Author
Level 2
May 28, 2020
This is not using the sling-model-exporter framework at all. And worse: It responds to all cq:Pages i.e. default-get-servlet and not only to specific page-resourcetypes!