通过liferay.expando以编程方式向用户添加自定义字段
我正在尝试将字段添加到通过liferay.expando以编程方式向用户添加自定义字段,liferay,liferay-6,expando,Liferay,Liferay 6,Expando,我正在尝试将字段添加到com.liferay.portal.model.User,这是一个使用Expando的额外属性。有人能给我解释一下这个方法是如何添加一个字段的,因为文档没有太多的描述 private void addUserCustomAttribute(long companyId, ExpandoTable userExpandoTable, String attributeName, int type) throws PortalException, SystemException
com.liferay.portal.model.User
,这是一个使用Expando
的额外属性。有人能给我解释一下这个方法是如何添加一个字段的,因为文档没有太多的描述
private void addUserCustomAttribute(long companyId, ExpandoTable userExpandoTable, String attributeName, int type) throws PortalException, SystemException {
ExpandoColumnLocalServiceUtil.getColumn(userExpandoTable.getTableId(), attributeName); //should be addColumn(long tableId, String name, int type) ???
} //and where can find type description couse i have very specific type, Map(String,Object) couse in ExpandoColumnConstants didn't see it
我从Liferay Wiki的网站上取的
我应该什么时候把这一切都说出来?在我的项目中放在哪里?什么样的改变是必需的,或者一切都需要改变才能称之为改变
一些好的教程会很好,因为从0到结尾很难找到一些东西,总是只找到一些没有解释的部分。问题不是很清楚。但是,如果您只是想为您的
用户添加一个自定义属性,那么您可以参考我的答案并复制以供参考:
用户实体的自定义字段可以通过以下方式创建:
控制面板->
门户->
自定义字段->
用户
可以按如下方式以编程方式创建和:
user.getExpandoBridge().addAttribute("yourCustomFieldKey");
然后将该值设置为:
user.getExpandoBridge().setAttribute("yourCustomFieldKey", "valueForCustomField");
如果您的自定义字段已经存在,您可以这样检查:
if (user.getExpandoBridge().hasAttribute("yourCustomFieldKey")) { ... };
数据存储在前缀为“EXPANDO”的表格中:
- EXPANDOCOLUMN:存储自定义字段键和其他设置
(包含tableId引用)
- EXPANDODATA:存储键的自定义字段值(包含
columnId和tableId引用)
- 可扩展:要为其添加liferay实体(用户)的存储
自定义字段
- EXPANDOROW:存储用户与其值之间的链接信息
(包含tableId和userId引用)
希望这有帮助。如果您的自定义字段是多值字段,您可以使用:
String customVal = "yourCustomFieldValue";
user.getExpandoBridge().setAttribute("yourCustomFieldKey", new String[] {customVal }, false);
最后一个参数设置为“false”可避免权限检查。其中包含一些有用的信息,但在何时何地使用这些信息,以及在任何时间(当然是在使用之前)、任何地点。如何创建地图字段?@user1506541请稍候,是否要存储地图类型的Expando?