Change Id for each component called by data-sly-resource | Community
Skip to main content
Level 3
Dec 23, 2021 6:48 AM UTC
Solved

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

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Anmol_Bhardwaj
Anmol_BhardwajAccepted solution
New Participant
Jan 5, 2022 1:42 PM UTC

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.

6 replies

Anmol_Bhardwaj
Anmol_BhardwajAccepted solution
New Participant
Jan 5, 2022 1:42 PM UTC

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.

Translate
Level 3
Jan 5, 2022 1:57 PM UTC

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

Translate
Level 3
Jan 6, 2022 6:00 AM UTC

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

Translate
Bhuwan_B
New Participant
Dec 23, 2021 7:59 AM UTC
Level 3
Dec 23, 2021 8:49 AM UTC

Will look into that. Thanks!

Translate