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.
Solved! Go to Solution.
Views
Replies
Total Likes
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.
@LyonMartin Please check below article for your reference:
https://blogs.perficient.com/2018/06/12/aem-development-quick-tip-component-unique-id/
Will look into that. Thanks!
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?
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.
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
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