This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. « Torna a Expando
Adding Custom Attributes to Communities
(Redirezionato da Adding an custom attribute to a Community)
Introduction #
This is an example of adding an Expando attribute called "title" on a com.liferay.portal.model.Group (a community).
Creating the Attribute #
void createAttribute(long companyId)
ExpandoBridgeImpl expandoBridge = new ExpandoBridgeImpl(com.liferay.portal.model.Group.class.getName());
if (expandoBridge.hasAttribute("title")) {
log.debug("attribute title already exists");
}
else {
log.info("adding title attribute");
expandoBridge.addAttribute("title");
}
}
Setting Permissions for Community Members #
void setPermissions(long companyId) {
ExpandoBridgeImpl expandoBridge = new ExpandoBridgeImpl(com.liferay.portal.model.Group.class.getName());
Role guest = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);
Role member = RoleLocalServiceUtil.getRole(companyId, RoleConstants.COMMUNITY_MEMBER);
ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
expandoBridge.getClassName(),
ExpandoTableConstants.DEFAULT_TABLE_NAME,
"title");
String[] actionsRO = new String[] { ActionKeys.VIEW };
String[] actionsRW = new String[] { ActionKeys.VIEW, ActionKeys.UPDATE };
// make sure the resource exists
Resource resource = ResourceLocalServiceUtil.addResource(
companyId,
ExpandoColumn.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(column.getColumnId()));
PermissionLocalServiceUtil.setRolePermissions(guest.getRoleId(), actionsRO, resource.getResourceId());
PermissionLocalServiceUtil.setRolePermissions(member.getRoleId(), actionsRW, resource.getResourceId());
}
Using the Attribute #
Java #
void updateTitle(Group group, String title) {
group.getExpandoBridge().setAttribute("title", title);
log.info("updated group " + group.getName() +
", set title = " + twinspace.getExpandoBridge().getAttribute(""));
}Velocity #
Use the community (=Group) title in the theme, for ex. in portal_normal.vm
#set ($community_title = $themeDisplay.getScopeGroup().getExpandoBridge().getAttribute("title"))
Troubleshooting #
Permissions Error #
- Instead of using the ExpandoBridge you can use ExpandoTableLocalServiceUtil and ExpandoColumnLocalServiceUtil. These services don't use permission checking. This is a bit more code.
- You can temporarily set a permissionChecker with PermissionThreadLocal.setPermissionChecker(pc). Don't forget to reset it to the original one after you are done.
91178 Visualizzazioni