2014-10-03 21 views
0

我嘗試使用liferay的API爲某些用戶添加其他電子郵件地址。 根據文檔,我覺得這一點:如何在liferay中使用EmailAddressLocalService

addEmailAddress(long userId, String className, long classPK, String address, int typeId, boolean primary) 

但我有點失落,我不知道如何以正確的方式 我有這個使用這個方法。

EmailAddressLocalServiceUtil.addEmailAddress(user.getUserId(),className, classPK, emailAddress2, typeId, false) 

我不知道怎麼去: -className -classPK -typeId

是有一些方法來獲得這個參數或者我需要手動指定該參數?

有幫助嗎?

回答

0

EmailAddressService用於存儲與不同的Liferay的實體相關的電子郵件(如用戶聯繫組織)。在聯繫人的情況下(您正在嘗試做什麼)ClassNameContact.class.getName()classPK是用戶的聯繫人對象ID。 TypeID是與當前實體相關的一個emaill地址類型的ID(對於聯繫的類型是電子郵件地址1,和)。

我有一個簡單的Groovy腳本,做如下:

  1. UserLocalServiceUtil獲取用戶
  2. 獲得適當的className,classPK和typeid的(從portal.properties默認定值)
  3. 向以前獲得的用戶添加新的電子郵件地址

Cod e:

import com.liferay.portal.model.Contact 
import com.liferay.portal.model.ListTypeConstants 
import com.liferay.portal.model.User 
import com.liferay.portal.service.EmailAddressLocalServiceUtil 
import com.liferay.portal.service.ServiceContext 
import com.liferay.portal.service.UserLocalServiceUtil 
import com.liferay.portal.util.PortalUtil 

User user = UserLocalServiceUtil.getUserByScreenName(PortalUtil.getDefaultCompanyId(), "someuser") 

String className = Contact.class.getName() 
long classPK = user.getContactId() 

int typeId = ListTypeConstants.CONTACT_EMAIL_ADDRESS_DEFAULT 

EmailAddressLocalServiceUtil.addEmailAddress(
     user.getUserId(), className, classPK, "[email protected]", typeId, false, new ServiceContext()) 
+0

謝謝你幫助我很多,最後我得到了正確的方法來使用這種方法 – 2014-10-06 16:07:30