Getting a custom user field value (expando) in Liferay

20,427

Solution 1

It was a security problem...

In com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.getData(String className, String tableName, String columnName, long classPK):

    if (ExpandoColumnPermission.contains(
            getPermissionChecker(), column, ActionKeys.VIEW)) {

        return expandoValueLocalService.getData(
            className, tableName, columnName, classPK);
    }
    else {
        return null;
    }

I only had to set the view permisson on the custom expando value, and everything worked fine.

Solution 2

I know it's a bit late, but for those still trying to figure out why a custom field turns out to be null (although it is clearly set and visible in Liferay), please make sure first that the custom field has the permissions properly set (Control Panel -> Custom fields -> User -> choose the appropiate custom field and click Action -> Permissions). By default, the Owner has all rights, but in my case, for example, I needed a View permission with a Guest account (user in the process of logging in). Hope this helps.

Share:
20,427
Daniel Kreiseder
Author by

Daniel Kreiseder

Hm... Yes.

Updated on October 08, 2020

Comments

  • Daniel Kreiseder
    Daniel Kreiseder over 3 years

    I added a custom user field in Liferay, and set a value on a specific user.

    How can I access this value programmatically?

    If I try this, I always get null:

    String customAttr = (String)user.getExpandoBridge().getAttribute("customAttr");
    

    user.getExpandoBridge().getAttribute("customAttr") returns a value of Type java.IO.Serializable.

    Maybe the cast here is wrong?

    But the Custom Attribute does exist (following code prints out the attribute key):

    for (Enumeration<String> attrs = user.getExpandoBridge().getAttributeNames(); attrs.hasMoreElements();)
        _log.info("elem: '" + attrs.nextElement() + "'");
    

    Somehow I miss the point here....