Friday, February 17, 2017

Pagination Problem in Liferay Search Container


We already see in detail how Search Container work in Liferay. But consider a scenario.

Let we have 9 records and we display 4 records on each page. So basically we have :-
a)2 pages with 4 records on each page
b)3rd page(last page) with only one record.

Now we delete record from 3rd page so ideally after deleting it will go to second page as now there are only 8 records . But in Liferay it will go to first page. So lets resolve this.Before reading this it is recommended to read search container in detail

Step 1:-Create Service Builder
My database table name is employee which contain only two fields eid and ename.

service.xml


Step 2:-Change your view
Inside your view paste this:-

view.jsp

Explanation:-
In the deleteRecord URL we send 4 parameters backURL, employeeId, cur and delta. Here :-
a)delta = number of records per page ie 4
b)cur = current page.
c)employeeId = id of employee which need to be deleted.
d)backURL = current URL





Step 3:-Change your Controller
Inside your java file paste this:-

Demo.java

Explanation:-
We fetch all values and delete the record and after that i find the total number of pages by some calculation.Then If maximum page is less than current page than i simple change the _cur parameter from backURL  with maxpage and send the response to that page.


Step 4:-Check Output
Now when you delete record from last page it will redirect to second last page.

You can Download Source code from  Pagination Problem in Liferay Search Container. 



No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!