Wednesday, 15 November 2017

Associate tags with our custom entity

Tags can be associated with our custom entity.

Add the following code in jsp:
/*Asset Tags Selector tag*/
<liferay-ui:asset-tags-selector/>
/*Theme define object is mandatory for asset tag selector*/
<liferay-theme:defineObjects /> 
And In controller:
 
/*Create service context object for sample class*/
ServiceContext serviceContext = ServiceContextFactory.getInstance(Sample.class.getName(), actionRequest);
/*Calling the asset entry add method*/
    AssetEntry assetEntry = AssetEntryLocalServiceUtil.updateEntry (serviceContext.getUserId(),serviceContext.getScopeGroupId(), Sample.class.getName(),sample.getId(),serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames());
Here I created service context object for my Sample entity.
And Using AssetEntryLocalServiceUtil.updateEntry() I am passing the required parameters.
And now you will find a new entry in AssetEntry and AssetEntry_AssetTag table.
And In the edit mode:
In jsp:
Get the tag names and make it as comma separated string.
And Pass it to curTags
/*Get your tag names*/
String tagNames = "tag1,tag2,tag3";
/*Give your tag names here*/ 
<liferay-ui:asset-tags-selector curTags="<%=tagNames %>"/>
Add,Edit and Delete can be easily done in liferay-ui:asset-tags-selector easily.

TEST

I am Java Developer. I have 6 year Experiance in this field and like to post in blogging. So keep sharing and like my post

0 comments:

Post a Comment

 

Copyright @ 2017 Liferay Article.