Custom fields of Organization in Liferay

I like this functionality in Liferay, we can customize liferay without creating Hook or Ext plugins. When I want to add Twitter field for organization to add twitter screen name, I was thinking I have to create a hook or ext plugins to do that. It would be very frustrating. Then my coworker told me I just need to go to Control panel as a admin, and in the left navigation, go to User and Organization. Next, you'll find a custom field link. Here you can add any custom fields you like.

Suppose you add a new column named Twitter. In the database, liferay doesn't change structure of organization_ table, what it does is to add a row in expando table. Custom field affects four tables. Let's list them:

1. expandocolumn: column name twitter will be stored here

2. expandorow: I don't know the one.

3. expandotable: Here specify the column belongs to organization_.

4. expandovalue: the value of twitter filed will be stored here

The next thing is how to get value of twitter:

protected String getTwitterScreenNameByOrganization(Organization org)
throws PortalException, SystemException {
ExpandoBridge bridge = org.getExpandoBridge();
String twitterScreenName = null;
if (bridge.hasAttribute("twitter")) {
twitterScreenName = (String) ExpandoValueLocalServiceUtil.getData(
bridge.getClassName(),
ExpandoTableConstants.DEFAULT_TABLE_NAME, "twitter",
org.getPrimaryKey());
}
return twitterScreenName;
}

Here it is! When you get the organization, you'll get it. The other way in the api is really easy, just use bridge.getAttribute("twitter"), but in my case, I always get null. I don't know the reason, so just use the way. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值