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

发布于 2024-07-26 14:03:50 字数 598 浏览 6 评论 0原文

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

我如何以编程方式访问该值?

如果我尝试这样做,我总是得到 null:

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

user.getExpandoBridge().getAttribute("customAttr") 返回 java.IO.Serialized 类型的值。

也许这里的演员阵容是错误的?

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-08-02 14:06:17

检查此处如何解决该问题当以 CSV 格式为用户导出自定义字段(expando 字段)时 http://liferay.bdedov.eu/2012/02/exporting-user-custom-fields-in-csv.html。 如果您想要导出用户并定义要包含在导出中的自定义字段,那么您只会收到自定义字段的空值。 查看这篇文章了解如何解决这个问题。

Check here how to fix the issue when custom fields (expando fields) are exported for users in CSV http://liferay.bdedov.eu/2012/02/exporting-user-custom-fields-in-csv.html. If you want to make an export of users and define custom fields to be included in the export then you receive only null values for for the custom fields. Check out this post to see how to fix this.

多孤肩上扛 2024-08-02 14:05:50

我知道现在有点晚了,但是对于那些仍然试图弄清楚为什么自定义字段结果为空的人(尽管它在 Liferay 中明确设置且可见),请首先确保自定义字段具有正确设置的权限(控制面板 -> 自定义字段 -> 用户 -> 选择适当的自定义字段并单击操作 -> 权限。 默认情况下,所有者拥有所有权限,但就我而言,例如,我需要具有来宾帐户(正在登录的用户)的查看权限。 希望这可以帮助。

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.

铁憨憨 2024-08-02 14:05:17

这是一个安全问题...

在 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;
    }

我只需设置自定义 Expando 值的视图权限,一切正常。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文