在Liferay中获取自定义用户字段值(expando)

Dan*_*der 6 java liferay expando

我在Liferay中添加了一个自定义用户字段,并为特定用户设置了一个值.

如何以编程方式访问此值?

如果我试试这个,我总是得到null:

String customAttr = (String)user.getExpandoBridge().getAttribute("customAttr");
Run Code Online (Sandbox Code Playgroud)

user.getExpandoBridge().getAttribute("customAttr")返回Type的值java.IO.Serializable.

也许这里的演员是错的?

但是自定义属性确实存在(以下代码打印出属性键):

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

不知怎的,我在这里错过了这一点......

Dan*_*der 8

这是一个安全问题......

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;
    }
Run Code Online (Sandbox Code Playgroud)

我只需要在自定义expando值上设置视图权限,一切正常.