Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jose Alvarez de Lara
portlet does not access table Liferay User
December 27, 2012 11:16 PM
Answer

Jose Alvarez de Lara

Rank: Junior Member

Posts: 45

Join Date: December 10, 2012

Recent Posts

Merry Christmas everyone emoticon,

I have a portle that prettends to access the table _User, get a list of all user and in case
of a selected one can update the first and last name.

But it does not work. No error, simplely it does anything.
Here is the main jsp code in the list.jsp file,
 1
 2<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
 3<%@ include file="/html/init.jsp" %>
 4
 5<h4>Test User List</h4>
 6
 7<%
 8int count = UserLocalServiceUtil.getUsersCount();
 9List<User> users = UserLocalServiceUtil.getUsers(0, count);
10%>
11
12<%
13PortletURL iteratorURL = renderResponse.createRenderURL();
14iteratorURL.setParameter("jspPage", "/html/list.jsp");
15
16PortletURL updateUserURL = renderResponse.createActionURL();
17updateUserURL.setParameter("jspPage", "/html/update.jsp");
18
19PortletURL detailsURL = renderResponse.createRenderURL();
20detailsURL.setParameter("jspPage", "/html/details.jsp");
21%>
22
23<liferay-ui:search-container delta="4" iteratorURL="<%= iteratorURL %>"
24    emptyResultsMessage="Sorry. There are no items to display.">
25
26    <liferay-ui:search-container-results
27        total="<%= users.size() %>"
28        results="<%= ListUtil.subList(users, searchContainer.getStart(), searchContainer.getEnd()) %>"
29    />
30       
31    <liferay-ui:search-container-row modelVar="user"
32        className="com.liferay.portal.model.User">
33       
34        <%
35            detailsURL.setParameter("userId", String.valueOf(user.getUserId()));
36            detailsURL.setParameter("backURL", themeDisplay.getURLCurrent());
37        %>
38        <liferay-ui:search-container-column-text name="User Full Name">
39            <aui:a href="<%= detailsURL.toString() %>"><%= user.getFullName() %></aui:a>
40        </liferay-ui:search-container-column-text>
41       
42        <% updateUserURL.setParameter("userId", String.valueOf(user.getUserId())); %>
43        <liferay-ui:search-container-column-text name="Update">
44            <a href="<%= updateUserURL.toString() %>">Update &raquo;</a>
45        </liferay-ui:search-container-column-text>
46       
47        <liferay-ui:search-container-column-jsp name="Actions"
48            path="/html/actions.jsp" />
49   
50    </liferay-ui:search-container-row>
51   
52    <liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
53
54</liferay-ui:search-container>
55
56<br/><a href="<portlet:renderURL/>">&laquo; Go Back</a>

it seems that exists an issue in the line,
<liferay-ui:search-container delta="4" iteratorURL="<%= iteratorURL %>"
emptyResultsMessage="Sorry. There are no items to display.">

I am not sure if delta="4" is correct. If someone could clear what it means
I shold be glad.

Here is the view.jsp file that causes no problem,
 1
 2<%@ include file="/html/init.jsp" %>
 3
 4Welcome to our Test User
 5
 6<%
 7    PortletURL listUsersURL = renderResponse.createRenderURL();
 8    listUsersURL.setParameter("jspPage", "/html/list.jsp");
 9%>
10
11<br/><a href="<%= listUsersURL.toString() %>">Show all users &raquo;</a>


Should be there some kind one who could help me.

Regards,
Jose
Jignesh Vachhani
RE: portlet does not access table Liferay User
December 27, 2012 11:23 PM
Answer

Jignesh Vachhani

Rank: Liferay Master

Posts: 772

Join Date: March 10, 2008

Recent Posts

Please try to set delta 20 and check the result again.
Also please put SOP to see that users object & count variable have any data or not.
Vishal Panchal
RE: portlet does not access table Liferay User
December 27, 2012 11:26 PM
Answer

Vishal Panchal

Rank: Expert

Posts: 276

Join Date: May 20, 2012

Recent Posts

Hi ,

First of all in <liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found">

delta - The number of results per page.
you have set it to "4" so only four records will be displayed on page at the same time.

Now everything looks fine I am not sure why you are not getting anything.

Are you getting the emptyResultsMessage as you set it to "Sorry. There are no items to display."

I think it should be coming from language.properties file and you need to specify key.

Kindly go through this link .
Hope it helps.

Thanks&Regards,
Vishal R. Panchal
Jose Alvarez de Lara
RE: portlet does not access table Liferay User
December 28, 2012 9:01 AM
Answer

Jose Alvarez de Lara

Rank: Junior Member

Posts: 45

Join Date: December 10, 2012

Recent Posts

Thanks for your quick reply.

The problem is the default user with email address default@liferay.com.
It seems that exixts some cause wich the jsp file can't display that user for.

I have changed the code as follows,

int count = UserLocalServiceUtil.getUsersCount();
List<User> users = UserLocalServiceUtil.getUsers(1, count);

avoiding the default user and now it works fine.

Regards,
Jose
Hitoshi Ozawa
RE: portlet does not access table Liferay User
December 29, 2012 2:30 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Instead of
int count = UserLocalServiceUtil.getUsersCount();
List<User> users = UserLocalServiceUtil.getUsers(0, count);


Should be using
UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS)

default@liferay.com user is probably causing some error because it's missing some required fields.

Also, are you sure you want to get all users because that will also return disabled users as well.
The better choice may be to use dynamicQuery() to select users to list.