Search code examples
liferayliferay-7

Listing and Displaying of Users and Organization in Liferay 7


I am trying to List all the users and organizations present in the db in liferay(7.1.2 ga3) on a JSP page.

I know i have to use UserLocalServiceUtil.getUsers() and OrganizationLocalServiceUtil.getOrganizations() inside render method to get the list of users and organizations. then i have to use renderUrl(which i don't know how to use) in jsp to display the lists.

I can retrieve the list of organizations and print them in console but for users nothing is getting printed in console.

Can some one please tell how to retrieve the list of users, and then what to write in jsp file to display them(users and organizations).

Not asking for code just a small example or steps or some document for this process.

I'll add my code below to show how i am trying.

@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException
{   
               //   for users (not getting printed in console)
    List<User> getUsers = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
    renderRequest.setAttribute("users", getUsers);
    _log.info("Users:" + getUsers);
            
              //    for organizations   
    List<Organization> getOrganizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
    renderRequest.setAttribute("organizations", getOrganizations);
    _log.info("Organizations:" + getOrganizations);
            
    super.render(renderRequest, renderResponse);
}


Solution

  • i'll add how i tried and it's working as expected.

    In my render method:

    //  for retrieving users from "user_" table in db
                
    List<User> getUsers = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
    renderRequest.setAttribute("users", getUsers);
                
    //  for retrieving organizations from "organization_" table in db
                
    List<Organization> getOrganizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
    renderRequest.setAttribute("organizations", getOrganizations);
    

    my listUser.jsp

    <tbody>
        <c:forEach var = "listUsers" items = "${users}">
            <tr>
                <td> <c:out value = "${listUsers.firstName}"/> </td>
                <td> <c:out value = "${listUsers.middleName}"/> </td>
                <td> <c:out value = "${listUsers.lastName}"/> </td> 
                <td> <c:out value = "${listUsers.emailAddress}"/> </td>
                <td> <c:out value = "${listUsers.screenName}"/> </td>   
                <td> 
                    <c:forEach var = "listContacts" items = "${contacts}">                  
                        <c:out value = "${listContacts.birthday}"/>  
                    </c:forEach>                    
                </td>
            </tr>
        </c:forEach>
    </tbody>
    

    my listOrganization.jsp

    <tbody>
        <c:forEach var = "listOrganizations" items = "${organizations}">
            <tr>
                <td> <c:out value = "${listOrganizations.name}"/> </td> 
            
    <!-- For Comparing countryid in organization_ table and countryid in country table in db to display country name present in country table-->                
                <td>    
                    <c:forEach var = "compareCountries" items = "${countries}"  >
                        <c:if test = "${listOrganizations.countryId eq compareCountries.countryId}">    
                            <c:out value = "${compareCountries.name}"/>     
                        </c:if> 
                    </c:forEach>        
                </td> 
             </tr> 
        </c:forEach>                                                                     
     </tbody>