Search code examples
liferayhookliferay-6liferay-themeliferay-aui

How can I fetch the existing table data in aportlet


I am trying to create the user by site admin so I have created a portlet which has basic user details form and in the action class I called the UserLocalServiceUtil.adduser(). Now the values are inserting into the DB in USER_. Now I want to display the list of created users by only site admin how can I do that? I have the following queries.

1) How can I fetch the values from USER_ in my portlet. Do I need to create the service builder OR are there API methods to fetch the values from the USER_ table?

2) I want to display only the users list which is created by site admin in my portlet. I don't want to display the whole company list of users. So How can I achieve this?

Suggest me any references or guidelines to do this.

Your help will be very much appreciated.


Solution

  • For Q1 :

    http://cdn.docs.liferay.com/portal/6.1/javadocs/com/liferay/portal/service/UserLocalServiceUtil.html#getUsers(int, int)

    This might help you. You don't need service builder for that. Just create a simple Liferay MVC portlet and call the relevant methods.

    for Q2 : I don't think this would be possible by API methods. What you can do is to set an expando variable for user at time of creation by site-admin. And @ time of fetching users, you can cross-check the value of that field manually.

    EDIT :

    One more point for suggestion : Never create user with Site-Admin role for user creation. This role is supposed to manage site & user assignment to the site. You can use more appropriate role i.e. Org-Admin rather than site-Admin.

    How to set an expando variable while adding the user?

    Liferay provides Expando API interface, which you can use while creation of user in your portlet. refer following links Developing with Expando, Liferay Expando API

    I hope this would be helpful to you.