Skip to main content
New Member
Jan 21, 2025 7:08 PM UTC
Solved

Dynamic node creation at runtime

Can we create nodes in the cq dialog at runtime?

The requirement is the dialog initially would only have a single dropdown with few fixed fields. So, when an option from the dropdown is selected let's say a value great is selected so when this action happened in the dropdown now it should map the value great to a json which has which component does great map to. Let's say great --- > mapped to "textfield". Now as soon as the backend mapping is done there should be a node created in the same dialog below the dropdown referring to textfield. Can someone help with the approach. we have tried few approaches, but any leads are welcome. TIN

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SreenivasBr
SreenivasBrAccepted solution
Level 4
Jan 21, 2025 8:28 PM UTC

I'm working on something. Yes, it is not recommended but could you please share if there is a way that you know of to add the nodes in jcr repository at in runtime?


If you want to add a node, use a dialog listener, call a servlet which will perform jcr operations. I am not sure whether this will work in AEM Cloud.

Some dialog listener reference which calls servlet - https://kiransg.com/tag/dialog-level-listener/

8 replies

SreenivasBr
Level 4
Jan 21, 2025 8:10 PM UTC

Is the requirement to show or hide a field based on dropdown selection?

Translate
New Member
Jan 21, 2025 8:13 PM UTC

No. Not exactly hiding or showing fields. But when the dropdown value ex: "great" is selected, it is mapped to a OOTB component. According to that mapping we have to create a node at runtime.

 

Translate
SreenivasBr
Level 4
Jan 21, 2025 8:17 PM UTC

Do you mean that component should be added as a child component? Why do you want to change the dialog nodes? It is not recommended to change dialog nodes dynamically. Content change is fine.

Translate
Anudeep_Garnepudi
Community Advisor
Community Advisor
Jan 22, 2025 2:40 AM UTC

@preethi1234  I see there is no need of creating dialog field on fly. Instead have the textfield hidden by default and show/hide based on you dropdown change listener.

Translate
AG
giuseppeb563528
New Member
Jan 23, 2025 5:04 PM UTC

I strongly recommend avoiding the complexity of creating dialog nodes at runtime. Instead, consider using a well-established practice of showing or hiding fields based on the value selected in a drop-down menu. You can even group multiple fields together to enhance the user experience.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager-blogs/show-hide-cq-dialog-fields-based-on-drop-down-selection-in-aem/ba-p/563950 

Translate
kautuk_sahni
Level 9
Feb 10, 2025 10:31 AM UTC

@preethi1234 Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Translate
Kautuk Sahni