I want to display users list on liferay. and I am having problem with it. Here is my action class.
public void userList(ActionRequest actionRequest, ActionResponse actionResponse) throws SystemException {
// Todo Logic for user code
try {
int countUser = UserLocalServiceUtil.getUsersCount();
log.info("User Present In DB" + countUser);
List < User > users = UserLocalServiceUtil.getUsers(0, countUser);
PortletSession sessions = actionRequest.getPortletSession();
sessions.setAttribute("users", users);
log.info("Session set from My Portlet" + sessions.getAttribute("users"));
for (User user: users) {
if (user != null) {
log.info("UserID--:" + user.getUserId() + "UserCompanyID-:" + user.getCompanyId() + "UserEmail-:" + user.getEmailAddress() +
"UserScreenName--:" + user.getScreenName());
}
}
and how I am trying to get the users list on jsp.
<%@page import="com.test.UserList.userList"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@page import="javax.portlet.PortletSession"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<%
PortletSession session2 = renderRequest.getPortletSession();
ArrayList<User> users = (ArrayList) session2.getAttribute("users");
if(users!=null){
%>
<b>Name: </b><%=users.get(users) %>
<%} %>
and i am getting the value is null i want to display all the users name in list
There is no issue with your logic in putting user-list in session, the list is getting populated and set in session accurately. However, on JSP, there are couple of issues:
UnmodifiableList cannot be cast to java.util.ArrayList
) for user-list.So, you need to do as following on your JSP:
(Tested Code)