Hi here I'm sharing the way to create new custom Attribute in User tab of control Panel by coding in Liferay 5.2.
Code :
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
User userObj = UserLocalServiceUtil.getUser(themeDisplay.getUserId());
ExpandoBridge expandoBridge =ExpandoBridgeFactoryUtil.getExpandoBridge(User.class.getName());
if (!expandoBridge.hasAttribute("testCustomAttributeName"))
{
expandoBridge.addAttribute("testCustomAttributeName");
}
It will check whether customAttribute name as testCustomAttributeName is already exist or not if it is not there then add in Custom Attibute.
If you want to add default value to that Custom Attribute than add following line at end of code.
userObj.getExpandoBridge().setAttribute("testCustomAttributeName", "AARAV");
It will set testCustomAttributeName's value as AARAV for that user only .