To Adding Custom Attributes Through Control Panel the following need to be done.
1 . we have to add an entry in liferay-portlet.xml for the particular portlet.
In my case i have add custom field for user group.I have added following tag in liferay-portlet.xml for the user_groups_admin (127) Portlet
4.Now you have to update jsp through the hook to display(view) and edit ,in detailed page of entty
my case:edit_user_group.jsp
Now It will save the usergroup attributes
1 . we have to add an entry in liferay-portlet.xml for the particular portlet.
In my case i have add custom field for user group.I have added following tag in liferay-portlet.xml for the user_groups_admin (127) Portlet
<custom-attributes-display>com.liferay.portlet.usergroupsadmin.UserGroupCustomAttributesDisplay</custom-attributes-display>2.Write a class to return class name and Icon path.
3.Now we have to deploy the ext as you have modified out of the box portlet.package com.liferay.portlet.usergroupsadmin;import com.liferay.portal.model.UserGroup;import com.liferay.portal.theme.ThemeDisplay;import com.liferay.portlet.expando.model.BaseCustomAttributesDisplay;public class UserGroupCustomAttributesDisplay extends BaseCustomAttributesDisplay {public static final String CLASS_NAME = UserGroup.class.getName();@Overridepublic String getClassName() {return CLASS_NAME;}@Overridepublic String getIconPath(ThemeDisplay themeDisplay) {return "/html/icons/user_groups_admin.png";}}
4.Now you have to update jsp through the hook to display(view) and edit ,in detailed page of entty
my case:edit_user_group.jsp
5.Now we have to save custom fields,so we have to add following code in action class before calling update or adding functionality.<liferay-ui:custom-attribute-listclassName="com.liferay.portal.model.UserGroup"classPK="<%= userGroup!= null ? userGroup.getUserGroupId() : 0 %>"editable="<%= true %>"label="<%= true %>"/>
Note:if add or update functions are having serviceContext as parameter then you have to get service Context and passServiceContext serviceContext = ServiceContextFactory.getInstance(UserGroup.class.getName(), actionRequest);userGroup.setExpandoBridgeAttributes(serviceContext);UserGroupLocalServiceUtil.updateUserGroup(userGroup);
Now It will save the usergroup attributes
Thanks for the useful information :-)
ReplyDeleteHi:
ReplyDeleteI want to add additional fields to the Tasks, possible?
Thanks