Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a custom user field value (expando) in Liferay

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....

like image 242
Daniel Kreiseder Avatar asked Jul 15 '09 11:07

Daniel Kreiseder


1 Answers

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.

like image 161
Daniel Kreiseder Avatar answered Nov 15 '22 00:11

Daniel Kreiseder