I am developing a Portlet with Liferay (using liferay-ui in the JSP) and SpringMVC.
I have the following code in my JSP:
<liferay-ui:search-container delta="5" emptyResultsMessage="no books!">
<%
List<Book> bookList = (List<Book>)request.getAttribute("bookList");
List<Book> bookListView = ListUtil.subList(bookList, searchContainer.getStart(), searchContainer.getEnd());
%>
<liferay-ui:search-container-results results="<%= bookListView %>" total="${numberOfBooks}">
</liferay-ui:search-container-results>
...
I'd really like to get rid of the Java Code Block in the JSP and have the bookListView as model attribute just like numberOfBooks in the above code.
However, I can't find a way to access searchContainer from the Spring Controller to get the start and end of the pagination...
Any ideas? Thx!
Create a suitable SearchContainer in your controller and add it to your model. As Prakash K already said this SearchContainer could look like this:
Because of the two parameter renderRequest and renderResponse you can not use the @ModelAttribute annotation to add the SearchContainer as a model attribute.
Then the JSP can be written like this:
The attribute deltaParam can be used to configure the used URL parameter
This might work for you:
Or else,
You can get the parameters from request:
delta=20
&cur=2
where
cur
is the current page which is requested anddelta
is the total number of items on a page.With this you can calculate the start (0,20,40, ...) and end (19,39,59, ...) as does liferay's
SearchContainer
with this method: