<%@page import="com.liferay.portal.kernel.util.ListUtil"%> <%@page import="com.liferay.portal.service.UserLocalServiceUtil"%> <%@page import="com.liferay.portal.model.User"%> <%@page import="java.text.SimpleDateFormat"%> <%@page import="java.util.List"%> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> <portlet:defineObjects /> <% SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy"); %> <liferay-ui:search-container delta="5" var="usersContainer" emptyResultsMessage="No Data to Display." > <% List<User> users = UserLocalServiceUtil.getUsers(-1, -1); List<User> usersResults = ListUtil.subList( users, usersContainer.getStart(), usersContainer.getEnd()); int totalUsers = UserLocalServiceUtil.getUsersCount(); %> <liferay-ui:search-container-results results="<%= usersResults %>" total="<%= totalUsers %>" /> <liferay-ui:search-container-row className="com.liferay.portal.model.User" keyProperty="userId" modelVar="user"> <liferay-ui:search-container-column-text name="User ID" property="userId" /> <liferay-ui:search-container-column-text name="First Name" property="firstName" /> <liferay-ui:search-container-column-text name="Email Address" property="emailAddress" /> <liferay-ui:search-container-column-text name="Created Date" value="<%= sdf.format(user.getCreateDate()) %>" /> </liferay-ui:search-container-row> <liferay-ui:search-iterator paginate="true" /> </liferay-ui:search-container>
The SimpleDateFormat is used to format the Created Date column that we will be showing in the Search Container.
<% SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy"); %>
The <liferay-ui:search-container> Tag, initializes the Search Container. Note the usersContainer variable name that has been assigned to it. This will be used to get the Start and End position of the Search Container.
<liferay-ui:search-container delta="5" var="usersContainer" emptyResultsMessage="No Data to Display." >
The list of Users present in liferay is retrieved. ListUtil.subList picks out only the Users that have to be displayed in the Search Container based on the usersContainer.getStart() and usersContainer.getEnd() position.
<% List<User> users = UserLocalServiceUtil.getUsers(-1, -1); List<User> usersResults = ListUtil.subList( users, usersContainer.getStart(), usersContainer.getEnd()); int totalUsers = UserLocalServiceUtil.getUsersCount(); %>
The list and total number of users present in Liferay is assigned to the <liferay-ui:search-container-results> tag.
<liferay-ui:search-container-results results="<%= usersResults %>" total="<%= totalUsers %>" />
Create a <liferay-ui:search-container-row> which will contain the Columns and display the Data to the User.
<liferay-ui:search-container-row className="com.liferay.portal.model.User" keyProperty="userId" modelVar="user">
Now to select what data to be displayed to the User. The Columns that need to be displayed are specified below. I have selected the User ID, First Name, Email Address and Created Date. The property represents the name given in the Service Builder. This is the variable name present in the User Class.
<liferay-ui:search-container-column-text name="User ID" property="userId" /> <liferay-ui:search-container-column-text name="First Name" property="firstName" /> <liferay-ui:search-container-column-text name="Email Address" property="emailAddress" /> <liferay-ui:search-container-column-text name="Created Date" value="<%= sdf.format(user.getCreateDate()) %>" />
The Iterator Tag is Required. Without it, the Search container will not work as expected.
<liferay-ui:search-iterator paginate="true" />
Thanks for sharing,
ReplyDeleteSecurity Cabin in Chennai|Mobile toilet Cabin in Chennai