我对标签和用户有以下要求。
- 标签应根据文本框
- 基于搜索后的电子邮件地址
- 应该有为用户添加/修改多个标签的选项基于他们在文本框中指定的电子邮件ID
我已经完成了为用户添加标签的编码,如下
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>
操作类:
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。但如果我想删除特定用户的标签,我该怎么做,如果有任何API或标签,请指导我。
为了检索基于文本框中指定的emailAddress的标签,我只是通过查询表单表AssetEntry_AssetTags来使用ServiceBuilder概念。显示给定emailAddress可用的标签是正确的方法吗。
您应该能够通过下面的API方法获得与用户实体关联的资产标签。com.liferay.portlet.asset.service.AssetTagLocalServiceUtil
public static java.util.List<com.liferay.portlet.asset.model.AssetTag> getTags(
long classNameId, long classPK)
其中classpk将是userId,classNameId将是User类。
希望这能有所帮助。