Foros de discusión

pagination is not working with <liferay-ui:searchContainer>tag

Ravinder karnati, modificado hace 6 años.

pagination is not working with <liferay-ui:searchContainer>tag

New Member Mensajes: 7 Fecha de incorporación: 20/09/17 Mensajes recientes
i am new to liferay , i have developed the services , persistence ,model layers and i have called EmployeeLocalServiceUtil.getEmployee(emp); method in portlet or controller and i kept it in request attribute and passed to jsp and i tried to display them using the search container
and i want page nation also but i am not getting its effect on browser (i am getting records on jsp but pagination if not showing ) can anybody help me
the code in portlet(controller) is

public void getEmployeeByNameByDynamicQuery(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
// local variabel declaration
String halfName = "";
DynamicQuery dynamicQuery = null;
List<Employee> list = null;

// read request param values
halfName = ParamUtil.getString(actionRequest, "halfname");
// get query object
dynamicQuery = DynamicQueryFactoryUtil.forClass(Employee.class);

// add any criteria to query
dynamicQuery.add(RestrictionsFactoryUtil.like("empName", halfName));
// execute the query
list = EmployeeLocalServiceUtil.dynamicQuery(dynamicQuery);
// keep the data in request attribute
actionRequest.setAttribute("list", list);
actionResponse.setRenderParameter("jspPage", "/html/getemployeebyname/employeeByName.jsp");

}// method

and code in jsp is

<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ page import="com.vidyayug.service.model.Employee"%>
<%@ page import="java.util.*"%>

<portlet:defineObjects />

<%
List<Employee> list = (List) request.getAttribute("list");

if (Validator.isNull(list))
list = new ArrayList();
%>
<%
if (list.size() != 0) {
%>
<liferay-ui:search-container
emptyResultsMessage="Employee Records Was Not found" delta="5">
<liferay-ui:search-container-results results="<%=ListUtil.subList(list,searchContainer.getStart(),searchContainer.getEnd())%>" />


<liferay-ui:search-container-row
className="com.vidyayug.service.model.Employee" modelVar="emp"
keyProperty="Empid">
<liferay-ui:search-container-column-text name="EmployeeId"
property="empid" />
<liferay-ui:search-container-column-text name="EmpployeeName"
property="empName" />
<liferay-ui:search-container-column-text name="EmployeeSalary"
property="salary" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>

<%
}
%>
<portlet:actionURL var="actionUrl"
name="getEmployeeByNameByDynamicQuery" />
<h3>Welcome to Custom Sql query</h3>
<aui:form name="fm" action="<%=actionUrl%>" method="post">
<aui:input name="halfname" label="Enter Half EmployeeName" />
<aui:button type="submit" value="getEmployees" />
</aui:form>


<a href="<portlet:renderURL/>">&laquo; goback</a>
thumbnail
Andrew Jardine, modificado hace 6 años.

RE: pagination is not working with <liferay-ui:searchContainer>tag

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Hi Ravinder,

Welcome to Liferay. Just to keep in mind in the future, you should make sure that you format the code you add to the message using the <> button from the toolbar. It'll be easier to follow the code.

Right out the gate, one of the things that I see is that you are not setting the total results, so the search container doesn't know t hat there are more than 5 items to display. So something like this --

<liferay-ui:search-container-results>
&lt;%
total = list.size();

results=ListUtil.subList(list,searchContainer.getStart(),searchContainer.getEnd());

searchContainer.setTotal(total);
searchContainer.setResults(results);
%&gt;</liferay-ui:search-container-results>


You also haven't provided a iteratorURL on the <liferay-ui:search-container tag/>. So you'll need to create a renderURL, something like this (depending on what your view file that is used by your search container).

<liferay-portlet:renderurl varimpl="iteratorURL">
    <portlet:param name="mvcPath" value="/html/view.jsp.jsp" />
</liferay-portlet:renderurl>


and then you add that <%= iteratorURL %> to your search container tag.

One other thing that I would like to point out here. I noticed that you are using Dynamic QUeries to get the records. That is certainly one approach, but the one thing you should be aware of here is that Dynamic Queries forego any use of the cache. So that means that the query, even if just called, will be executed each time. There are other methods on the generated services that you can use that don't use dynamic queries where, under heavy load, you would get better results.
Ravinder karnati, modificado hace 6 años.

RE: pagination is not working with <liferay-ui:searchContainer>tag

New Member Mensajes: 7 Fecha de incorporación: 20/09/17 Mensajes recientes
Hi Andrew Jardine
Thank you for your response ,

i have tried that but i am getting the records on jsp page but i am not getting the that page nation effect on jsp page visually
means when pagination is happen on browser we are able to see like <-First,previous,Next,Last-> ,but
i am not seeing those options on portal page how to get them
thumbnail
Andrew Jardine, modificado hace 6 años.

RE: pagination is not working with <liferay-ui:searchContainer>tag

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
I'm not sure I understand what you mean. Let me explain what I understand you to be saying, and you can correct what I have not understood.

THe user goes to the page (first time). The page loads, and the initial set of 5 records is shown. Previously you said that there were no pagination controls (I believe) and based on this most recent reply, I think you are saying that you now see the controls on the page. When you click the controls, let's say the next page, on the server you see the correct "page" of results being calculated, but when it is rendered in the JSP, you still see the same initial set of results.

Is that it?

PS> If you can attach your code then I can always try it locally to see what is happening.
Ravinder karnati, modificado hace 6 años.

RE: pagination is not working with <liferay-ui:searchContainer>tag

New Member Mensajes: 7 Fecha de incorporación: 20/09/17 Mensajes recientes
actually i am displaying the records on jsp page but i am unable to see the controls on the page
thumbnail
Roman Novikov, modificado hace 5 años.

RE: pagination is not working with <liferay-ui:searchContainer>tag

Junior Member Mensajes: 39 Fecha de incorporación: 7/01/17 Mensajes recientes

Hello! I've got the same situation. Controls are absent. Could it be fixed somehow?


So.. "search-container-results" tag is not accepting "total" attribute. Then as I understand there must be a button "More.." instead of "First", "Next" and "Last". But there aren't any button by default. After I'd put  "searchContainer.setTotal(regionFilter.equals("-1") ? BanksL...", the common controls ("First", "Next", page_numbers, "Last") appeared.

Two questions:

1. Why the attribute "total" was removed from the tag while the "More..." button is not appearing by default?

2. How can I get "More.." button visible and functioning?