您的位置:首页 > Web前端

Custom fields of Organization in Liferay

2012-11-14 22:00 169 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐