In this article I am going to explain how to create the dropdown dynamically in a dialog using Granite Datasource object. Here we are creating Datasource object using the Java class that extends the WCMUsePojo class and then how Datasource is used within HTL.
If you want to display the items in dropdown dynamically then you can use the Datasource object. A drop-down control is populated by using a com.adobe.granite.ui.components.ds.DataSource object. For information, see DataSource. The below screenshot represents the items displayed in the dropdown dynamically.
Creating DataSource Object using Java class:
Step 1: Create the Java class which extends the WCMUsePojo and creating the Data source object in it. Below is the illustration of the java class that shows how to create the items dynamically.
Here is my simple dialog in the Hello world component which contains the text field(/apps/myHTL63/components/content/helloworld/cq:dialog/content/items/column/items). Add the Dropdown field in the dialog.
Step 5.1: Right click on /apps/myHTL63/components/content/helloworld/cq:dialog/content/items/column/items, select Create and Create Node. Enter the following values.
Step 5.2: Add the following properties to the tasks node:
This is how you locate the folder datasource in the dialog and call the datasource object from the java that we have created previously.
Note: If there are two datasource objects that created in the java class and you want to display the another datasource object as drop-down in the dialog, then make sure you have created the another folder for second datasource object i.e., under /apps/myHTL63/components/datasource as we created the mylist(/apps/myHTL63/components/datasource/mylist) in the previous illustration.
When you call the datasource object which is in Java class using HTL then all the countries will display as a drop-down control as shown in the below screenshot.
No related posts.
Myself Ratna Kumar, I am having 5.4 years of total IT experience and out of which 3 years of experience on AEM. I have worked on various versions of AEM i.e., CQ5.4, AEM 5.6.1, AEM 6.1 and AEM 6.2 versions. Also, I have vast experience in Java/J2EE technologies.
I am a quick learner and also used to help the community in Adobe HELPX and as well as in forums