Pages

Thursday, 21 March 2013

pagination in liferay

what is pagination?



  • Fetching millions of records from database consumes almost all CPU power and memory of machine.
  • Hence we break millions of records into small chunks showing limited number of records (say 20 or 30) per page. The best example of this is Google search pagination which allows user to navigate to next page by page number and explore limited records per pages.

i will explain step by step process what i did in my project

1.Create Service.xml file in /WEB-INF folder write the following entity in you'r xml.
    < entity name="search" local-service="true" remote-service="false" >
<column name="sid" type="long" primary="true" id-type="increment"></column>
<column name="enrollementno" type="long"></column>
<column name="firstname" type="String"></column>
<column name="lastname" type="String"></column>
<column name="address" type="String"></column>
</entity>
now build the service.
2.add the below code in web.xml.
      <taglib> 
         <taglib-uri>http://liferay.com/tld/aui</taglib-uri> 
           <taglib-location>/WEB-INF/tld/aui.tld</taglib-location>
     </taglib>

3.add the following code in your jsp .
   <%
       List<search> srch = searchLocalServiceUtil.getsearchs(0,-1);
      // System.out.println("Student size is " + srch.size());
%>
<liferay-ui:search-container delta="3" emptyResultsMessage="No Results Were found for the Selected Criteria">
<liferay-ui:search-container-results total="<%= srch.size() %>"    
                                                       results="<%= ListUtil.subList(srch,searchContainer.getStart(),searchContainer.getEnd()) %>"/>
<liferay-ui:search-container-row modelVar="searchlist" className="com.test.model.search" >
<liferay-ui:search-container-column-text name="sid"  > <%=searchlist.getEnrollementno()%> </liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name="FirstName" ><%=searchlist.getFirstname() %> </liferay-ui:search-container-column-text>
                                               <liferay-ui:search-container-column-text name="LastName" ><%=searchlist.getLastname() %></liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name="address"><%=searchlist.getAddress() %></liferay-ui:search-container-column-text>                                             
     </liferay-ui:search-container-row>
         <liferay-ui:search-iterator />
</liferay-ui:search-container>

import all packages that are required.
 Insert 6-10 records in you Database to understand the output .
 that's all you have done your work.
now pen your browser and ADD your portlet you can see your records

1 comment:

  1. What about the controller code?will it works in Liferay 7 using above code?

    ReplyDelete