Get list of users in liferay -
i want display users list on liferay. , having problem it. here action class.
public void userlist(actionrequest actionrequest, actionresponse actionresponse) throws systemexception { // todo logic 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 portlet" + sessions.getattribute("users")); (user user: users) { if (user != null) { log.info("userid--:" + user.getuserid() + "usercompanyid-:" + user.getcompanyid() + "useremail-:" + user.getemailaddress() + "userscreenname--:" + user.getscreenname()); } }
and how trying 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 getting value null want display users name in list
there no issue logic in putting user-list in session, list getting populated , set in session accurately. however, on jsp, there couple of issues:
- renderrequest undefined.
- cast exception (
unmodifiablelist cannot cast java.util.arraylist
) user-list. - you not iterating list , getting user objects properly.
so, need following on jsp:
<%@page import="java.util.arraylist"%> <%@page import="javax.portlet.renderrequest"%> <%@page import="com.liferay.portal.model.user"%> <%@page import="javax.portlet.portletsession"%> <% renderrequest renderrequest = (renderrequest) request.getattribute("javax.portlet.request"); portletsession session = renderrequest.getportletsession(); list<user> users = (list<user>) session.getattribute("users"); if(users != null){ for(user user : users){ %> <b>name: </b><%=user.getlastname() + ", " + user.getfirstname() %><br /> <%} }%>
(tested code)
Comments
Post a Comment