06 April, 2012

Pagination in Liferay

If you are looking solution  for pagination in Liferay 6.1,
Follow below steps to create pagination in liferay.



1) The first and fore most step is to define the pagination container, the liferay-ui 1tag provides a the search-container1 tag which could be used to initialize the container

<liferay-ui:search-container emptyResultsMessage="there-are-no-items" delta="10">
  • emptyResultsMessage : Used to display the message to the user when no records are found, a resource bundle key could be specified for internationalization
  • delta :  the default number of items that needs to be displayed on the page
2)  The next step is to manipulate  the result and set the same in pageContext of the JSP page, this is done using the liferay-ui’s search-container-results1,  when manipulating the result we need to set the following pageContext variables to enable the Liferay-ui tag to process and display them,
  • results – the variable that will hold the subList of the entire result set with its start determined by searchContainer.getStart() and end determined by searchContainer.getEnd(), where searchContainer is an implicit variable available to the page context after Step #1
  •  total – The total result set size , in our case 200 
<liferay-ui:search-container-results>
<%
List<ListItemModel> tempResults = PaginationUtil.getListItems(200);
results = ListUtil.subList(tempResults,searchContainer.getStart(),searchContainer.getEnd());
total = tempResults.size();
pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%>
</liferay-ui:search-container-results>
3) The third step of the implementation is to define the result row which is done using the liferay-ui’s search-container-row1  tag, this tag takes the following parameters,  
  • className : The model class that is contained in the result set returned by the PaginationUtil
  • keyProperty : The primary key or unique key property that will be used or passed to various actions
  • modelVar   :    The temporary variable where the current resultset object will be stored, typically an instance of className

<liferay-ui:search-container-row className="com.cignex.demo.portlets.ListItemModel" keyProperty="id" modelVar="listItemModel">
4) The fourth step of the implementation is to define the columns that will be displayed in the resulting table, this is done using the liferay-ui’s search-container-column-text  this tag takes the following two properties,
  • name  :  The HTML name attribute for the table column
  • property  : The model property form which the value of the column needs to be set

<liferay-ui:search-container-column-text name="id" property="id" />
5) The last and final step of the implementation is to define the paginator element of the results which will help in navigating across pages typically First, Next, Previous, Last etc.,  this is done using the liferay-ui’s  search-container-row

</liferay-ui:search-container-row>

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...