如何在 Liferay 中为用户添加 Add/Update/View 标签

How to Add/Update/View tags for the user in Liferay

我对标签和用户有以下要求。

我已经编写了如下代码来为用户添加标签

JSP:

<portlet:actionURL var="addTagsURL"  name="addTags"/>    
<aui:form action="<%=addTagsURL%>" method="post" name="submit">
    <aui:input name="emailAddress" id="emailAddress" label="Email Address">
        <aui:validator name="required" />       
    </aui:input>
    <liferay-ui:asset-tags-error />
    <aui:input name="tags" type="assetTags" />
    <div>
        <liferay-ui:asset-tags-selector />
    </div>
    <aui:input type="Submit" name="Submit" value="Submit"></aui:input>
</aui:form>

动作class:

public void addTags(ActionRequest actionRequest,ActionResponse actionResponse){
        String emailAddress=ParamUtil.getString(actionRequest, "emailAddress");
        log_.info("user email address from form========>"+emailAddress);
        ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);        
        User user;
        try {
            user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);
            ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
            AssetEntryLocalServiceUtil.updateEntry(user.getUserId(), themeDisplay.getScopeGroupId(),"com.liferay.portal.model.User", user.getUserId(),null, serviceContext.getAssetTagNames());
            log_.info("user email address========>"+user.getEmailAddress());
            log_.info("UserId is=========>"+user.getUserId());
            String tags[]=serviceContext.getAssetTagNames();
            log_.info("Tags are====>"+tags.toString());         
        } catch (PortalException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

通过上面的代码,我可以让 UI 将标签添加到 users.But 如果我想删除特定用户的标签我该怎么做,如果有 API 或标签在那里,请指导我。

为了基于文本框中指定的电子邮件地址检索标签,我只是通过查询表单表来使用 ServiceBuilder 概念 AssetEntry_AssetTags.Is 它是显示给定电子邮件地址可用标签的正确方法。

您应该能够通过以下 API 方法获取与用户实体关联的资产标签。 com.liferay.portlet.asset.service.AssetTagLocalServiceUtil

public static java.util.List<com.liferay.portlet.asset.model.AssetTag> getTags( long classNameId, long classPK)

其中 classpk 是用户 ID,classNameId 是用户 class。

希望对您有所帮助。