Wednesday, March 12, 2014

Custom Attributes in Liferay

Follow the steps for making custom attributes-
Go to Control Panel -> User - > Custom Attribute -> Add Custom Attribute
An Attribute is a key and type of the field (once saved) cannot be changed at all...
Accessing Custom Attribute Pragmatically:
ThemeDisplay themeDisplay=(ThemeDisplay)request.getAttribute(Web_Keys.THEME_DISPLAY);
User user = themeDisplay.getUser();
System.out.println(user.getExpendoBridge().getAttribute("CustomAttributeName"));
Setting Attribute Pragmatically:
ThemeDisplay themeDisplay =(ThemeDisplay)request.getAttribute(Web_Keys.THEME_DISPLAY);
User user = themeDisplay.getUser();
System.out.println(user.getExpendoBridge().setAttribute("CustomAttributeName","Value"));
Adding custom Attribute form element at Sign In Portlet
write the following code in /root/html/portlet/login/create_account.jsp
<liferay ui:custom-attribute-list
                  className="com.liferay.portal.model.user"
                  editable="<%=true%>"
                  label="<%=true%>">
but this will not visible to due to permission. So, login as admin and provide permission to guest to see and modify custom field through control panel.

No comments:

Post a Comment