Create Datalist Using 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.

String DATALIST_CONTAINER = "dataLists";

SiteInfo siteInfo = this.siteService.createSite (TEST_SITE_PRESET, siteName, siteName, DESCRIPTION_TEST_THIS_IS_MY_DESCRIPTION, SiteVisibility.PRIVATE);
 
//NodeRef dataListContainer = siteService.createContainer(siteName, DATALIST_CONTAINER, ContentModel.TYPE_CONTAINER, null);

//if the datalist container does not exist then it will create a new one based on the create boolean parameter
NodeRef dataListContainer = SiteServiceImpl.getSiteContainer(siteName, DATALIST_CONTAINER, true, siteService, transactionService, taggingService);

Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_TITLE, "Demo");
contentProps.put(ContentModel.PROP_DESCRIPTION, "Demo Datalist");
contentProps.put(DataListModel.PROP_DATALIST_ITEM_TYPE, "YOUR DATALIST ITEM TYPE");

nodeService.createNode(dataListContainer, ContentModel.ASSOC_CONTAINS, QName.createQName(DataListModel.DATALIST_MODEL_PREFIX, "Demo"), DataListModel.TYPE_DATALIST, contentProps);

Hope this helps someone.

 

Up Next
    Ebook Download
    View all
    Learn
    View all