Create Datalist Using Alfresco Java API

In this article you will learn how to create a datalist using the Alfresco Java API.

Step 1: First create the site using siteService.
  
Step 2: Create the datalist container using siteService or SiteServiceImpl. 
 
Step 3: Create the necessary properties for the datalist. 
 
Step 4: Create the datalist using nodeService. 
  1. String DATALIST_CONTAINER = "dataLists";  
  2.   
  3. SiteInfo siteInfo = this.siteService.createSite (TEST_SITE_PRESET, siteName, siteName, DESCRIPTION_TEST_THIS_IS_MY_DESCRIPTION, SiteVisibility.PRIVATE);  
  4.    
  5. //NodeRef dataListContainer = siteService.createContainer(siteName, DATALIST_CONTAINER, ContentModel.TYPE_CONTAINER, null);  
  6.   
  7. //if the datalist container does not exist then it will create a new one based on the create boolean parameter  
  8. NodeRef dataListContainer = SiteServiceImpl.getSiteContainer(siteName, DATALIST_CONTAINER, true, siteService, transactionService, taggingService);  
  9.   
  10. Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();  
  11. contentProps.put(ContentModel.PROP_TITLE, "Demo");  
  12. contentProps.put(ContentModel.PROP_DESCRIPTION, "Demo Datalist");  
  13. contentProps.put(DataListModel.PROP_DATALIST_ITEM_TYPE, "YOUR DATALIST ITEM TYPE");  
  14.   
  15. nodeService.createNode(dataListContainer, ContentModel.ASSOC_CONTAINS, QName.createQName(DataListModel.DATALIST_MODEL_PREFIX, "Demo"), DataListModel.TYPE_DATALIST, contentProps);  
Hope this helps someone.