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

Change Id for each component called by data-sly-resource

Avatar

Level 3

Is there a way to change component's ID when called by data-sly-resource?
I have a object list and uses data-sly-resource to iterate each resource.
The problem is that the IDs for each component called uses the ID of the parent component, therefore encountering an issue with ID not being unique.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can always write a java function in the use class of the parent component ( from where you are calling data-sly-resource) or the component itself.

 

The function should return a random integer value and then you can use that value to assign it to the element id.

View solution in original post

6 Replies

Avatar

Level 3

Doesn't work on my end. Called components still uses the ID of the parent (it still shows something like "calledComponentName-{parentHash}"). Called components don't even show in the CRXDE, I guess that's why it wont work.
Any solutions for this?

Avatar

Correct answer by
Community Advisor

You can always write a java function in the use class of the parent component ( from where you are calling data-sly-resource) or the component itself.

 

The function should return a random integer value and then you can use that value to assign it to the element id.

Avatar

Level 3

Hi AnmolBhardwaj1808 , I tried creating a resource map on my end to add the ID (as well as the item index), it works, though I'm having problems passing this value to the "child" component. 

I found this one in the stackoverflow, though I still haven't figured out how to use the selectors in data-sly-resource. 
https://stackoverflow.com/questions/35188462/passing-selector-in-data-sly-resource-in-sightly

Thanks,
Martin

Avatar

Level 3

About this, I misplaced the creation of id to the resouce creation. 
I just added it to the resource map and it's now working.

Many Thanks, 
Martin