Is it possible to add Extra Fields Under Create User in Liferay

你离开我真会死。 提交于 2019-12-18 11:57:41

问题


I am using Liferay 6 for portal Development . During Creating Users under Liferay , i need to add some extra Fields also ?? Please let me know if this is ppossible or not ??

Please see the screen shot attached here , and also please let me know in which table this will be stored in Database ??


回答1:


Yes, you can use Custom Attributes functionality for liferay entities (in your case, User) and can add as many extra fields as necessary for each liferay entity.

Custom field for the user-entity can be created through:
Control Panel -> Portal -> Custom Fields -> User.

And programmatically can be created as follows:

user.getExpandoBridge().addAttribute("yourCustomFieldKey");

Then set the value as:

user.getExpandoBridge().setAttribute("yourCustomFieldKey", "valueForCustomField");

If your custom field is already present you can check like this:

if (user.getExpandoBridge().hasAttribute("yourCustomFieldKey")) { ... };

The data is stored in tables prefixed with "EXPANDO":

  • EXPANDOCOLUMN: stores the custom field key and other settings (contains the tableId refrences)
  • EXPANDODATA: stores the custom field value for the key (contains the columnId and tableId refrences)
  • EXPANDOTABLE: stores for which liferay entity (user) are you adding the custom field
  • EXPANDOROW: stores linking information between a user and its values (contains tableId and userId refrences)

Hope this helps.




回答2:


yes, you can add custom fields to user-entity and add them the field-values to user:

user.getExpandoBridge().addAttribute(...);

Custim field for the user-entity you can create by Control Panel Portal->Custom Fields or programmaticaly at liferay start.

The data will be stored in ExpandoValue tables.




回答3:


Just in case somebody try to retrieve the values from the custom fields and is having problems with null values returned by the method user.getExpandoBridge().getAttribute("yourCustomFieldKey") (even when you followed the threads about permissions), I found other way to retrieve the Custom Fields values:

ExpandoTable table = ExpandoTableLocalServiceUtil.getDefaultTable(user.getCompanyId(), User.class.getName() );
ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(table.getTableId(), "yourCustomFieldKey");
ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.getValue(table.getTableId(), column.getColumnId(), user.getUserId());

Then you can do a simple (if the field is text) expandoValue.getString();

Not so pretty, but do the work.




回答4:


User creation page in liferay can be customized. You can infact decide which fields to be present in the user creation page. More about this in here.




回答5:


Use the following commands if you get the permission problem in adding or setting attribute.

user.getExpandoBridge().addAttribute("yourCustomFieldKey",false);
user.getExpandoBridge().setAttribute("yourCustomFieldKey", "valueForCustomField",false);


来源:https://stackoverflow.com/questions/10136753/is-it-possible-to-add-extra-fields-under-create-user-in-liferay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!