Change Id for each component called by data-sly-resource | Community
Skip to main content
Level 3
December 23, 2021
Solved

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

  • December 23, 2021
  • 2 replies
  • 2825 views

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.
Best answer by Anmol_Bhardwaj

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.

2 replies

Bhuwan_B
Community Advisor
Community Advisor
December 23, 2021
Level 3
December 23, 2021

Will look into that. Thanks!

Anmol_Bhardwaj
Community Advisor
Anmol_BhardwajCommunity AdvisorAccepted solution
Community Advisor
January 5, 2022

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.

Level 3
January 5, 2022

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

Level 3
January 6, 2022

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