Dynamic node creation at runtime | Community
Skip to main content
January 21, 2025
Solved

Dynamic node creation at runtime

  • January 21, 2025
  • 4 replies
  • 930 views

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

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/

4 replies

SreenivasBr
Level 4
January 21, 2025

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

January 21, 2025

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.

 

SreenivasBr
Level 4
January 21, 2025

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.

Anudeep_Garnepudi
Community Advisor
Community Advisor
January 22, 2025

@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.

AG
giuseppeb563528
January 23, 2025

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 

kautuk_sahni
Community Manager
Community Manager
February 10, 2025

@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!

Kautuk Sahni