2016-06-13 79 views
0

我有一個名爲Skills in liferay 6.2用戶配置文件的自定義字段(即當您單擊我的帳戶 - >詳細信息部分時)。目前,此技能字段接受多個文本值並顯示爲純文本條目。我想要顯示作爲標籤輸入的每項技能。是否有任何可用的UI組件來執行此任務?我檢查了Liferay文檔上的標籤管理。他們建議從Admin-> content部分添加標籤。不過,我想在用戶輸入技能值時即時創建標籤。在Liferay用戶portlet中添加自定義字段值作爲標籤

回答

0

我的方法是使用liferay ui資產標籤選擇器。它提供了UI組件分配和顯示標籤

<label>Skills</label> 
     <liferay-ui:asset-tags-selector 
      className="<%= User.class.getName() %>" 
      classPK="<%= selUser != null ? selUser.getUserId() : 0 %>" 
     /> 
1

如果我得到你的權利,你希望用戶輸入的技能要創建作爲門戶網站的標籤。

爲此,您需要創建用於創建用戶帳戶的自定義CreateAccountAction

這是通過使用Liferay Extension Plugin項目在Liferay中擴展addUser()方法完成的。

則擴展addUser()方法裏面添加邏輯來創建AssetCategoryAssetVocabulary和標籤

這裏是一個可能的方法來創建技能標籤的例子

protected AssetCategory addAssetCategory(long userId, 
     long parentCategoryId, String title, long vocabularyId, 
     ServiceContext serviceContext) throws Exception { 

    Map<Locale, String> titleMap = new HashMap<Locale, String>(); 

    setLocalizedValue(titleMap, title); 

    return AssetCategoryLocalServiceUtil.addCategory(userId, 
      parentCategoryId, titleMap, null, vocabularyId, null, 
      serviceContext); 

} 

protected AssetVocabulary addAssetVocabulary(long userId, String title, 
     ServiceContext serviceContext) throws Exception { 

    Map<Locale, String> titleMap = new HashMap<Locale, String>(); 

    setLocalizedValue(titleMap, title); 

    return AssetVocabularyLocalServiceUtil.addVocabulary(userId, 
      StringPool.BLANK, titleMap, null, null, serviceContext); 
} 

確保您使用serviceContext.setAddGroupPermissions(true)serviceContext.setAddGuestPermissions(true)在調用方法之前確保獲得適當的權限

+1

創建ServiceContext像這樣 'ServiceContext serviceContext = ServiceContextFactory.getInstance(BlogsEntry.class.getName(),portletRequest);' –

+0

其實我使用Bootstrap標籤輸入插件來解決當時的這些問題。感謝這些評論,如果我們再次需要這些要求,我會再檢查它 – user596502

+0

沒問題。很高興能貢獻。 –

相關問題