Listing user's information programatically

From OpenCms Wiki
Jump to: navigation, search

This example is for OpenCMS 7.0.3, in the version 7.0.4 some of the methods used in this scrip are deprecated, because the new Version adds the Organization Unit.

Code

CmsObject cmsAdminObj = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
CmsDefaultUsers cmsUsers = new CmsDefaultUsers();
List users = cmsAdminObj.getUsersOfGroup(cmsUsers.getGroupUsers());  
Iterator iterator = users.iterator();
while (iterator.hasNext()) {
       CmsUser user = (CmsUser)iterator.next();
       // Access the user information

}


JSP Example


<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ page import="org.opencms.file.*, 
                 org.opencms.jsp.CmsJspNavElement, 
                 org.opencms.db.CmsDefaultUsers, 
                 org.opencms.main.OpenCms,
                 org.opencms.file.CmsUser,
                 java.util.List,
                 java.util.Iterator" %>


<jsp:useBean id="cms" class="org.opencms.jsp.CmsJspActionElement">
    <% cms.init(pageContext, request, response);  %>
</jsp:useBean>
                
<%@ page import="java.util.*" %>


<%
CmsObject cmsAdminObj = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
CmsDefaultUsers cmsUsers = new CmsDefaultUsers();
List users = cmsAdminObj.getUsersOfGroup(cmsUsers.getGroupUsers());  
Iterator iterator = users.iterator();
while (iterator.hasNext()) {
       CmsUser user = (CmsUser)iterator.next();
%>
	<%= user.getFullName() %>: <%= user.getEmail() %>	<br/>
<%
}
%>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox