java 在 Liferay 中获取自定义用户字段值 (expando)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1130958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting a custom user field value (expando) in Liferay
提问by Daniel Kreiseder
I added a custom user field in Liferay, and set a value on a specific user.
我在 Liferay 中添加了一个自定义用户字段,并为特定用户设置了一个值。
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.
user.getExpandoBridge().getAttribute("customAttr")返回 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....
不知何故,我错过了这里的重点......
回答by Daniel Kreiseder
It was a security problem...
这是一个安全问题......
In com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.getData(String className, String tableName, String columnName, long classPK):
在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.
我只需要在自定义 expando 值上设置视图权限,一切正常。
回答by Andra
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.
我知道这有点晚了,但是对于那些仍在试图弄清楚为什么自定义字段结果为空的人(尽管它在 Liferay 中已明确设置并可见),请首先确保自定义字段具有正确设置的权限(控制面板 -> 自定义字段 -> 用户 -> 选择合适的自定义字段并单击操作 -> 权限)。默认情况下,所有者拥有所有权限,但在我的情况下,例如,我需要具有访客帐户(登录过程中的用户)的查看权限。希望这可以帮助。
回答by Liferay Blogger
Check herehow 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 postto see how to fix this.
在此处查看如何在 CSV http://liferay.bdedov.eu/2012/02/exporting-user-custom-fields-in-csv.html 中为用户导出自定义字段(扩展字段)时解决问题。如果您想导出用户并定义要包含在导出中的自定义字段,那么您只会收到自定义字段的空值。查看此帖子以了解如何解决此问题。

