本文介绍了在SpringMVC Controller中从Liferay搜索容器访问分页信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用Liferay(在JSP中使用liferay-ui)和SpringMVC开发Portlet.

I am developing a Portlet with Liferay (using liferay-ui in the JSP) and SpringMVC.

我的JSP中包含以下代码:

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>
  ...

我真的很想摆脱JSP中的Java代码块,并将bookListView作为模型属性,就像上面代码中的numberOfBooks一样.

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.

但是,我找不到从Spring Controller访问searchContainer来获取分页的开始和结束的方法...

However, I can't find a way to access searchContainer from the Spring Controller to get the start and end of the pagination...

有什么想法吗?谢谢!

推荐答案

这可能对您有用:

SearchContainer<Book> searchContainer = new SearchContainer<Book>(renderRequest, renderResponse.createRenderURL(), null, "there are no books");

否则,

您可以从请求中获取参数:delta=20& cur=2
其中,cur是当前请求的页面,而delta是页面上的项目总数.
借助此功能,您可以计算出开始(0,20,40,...)和结束(19,39,59,...),就像liferay的 SearchContainer 与此方法:

You can get the parameters from request: delta=20 & cur=2
where cur is the current page which is requested and delta 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:

private void _calculateStartAndEnd() {
    _start = (_cur - 1) * _delta;
    _end = _start + _delta;

    _resultEnd = _end;

    if (_resultEnd > _total) {
        _resultEnd = _total;
    }
}

这篇关于在SpringMVC Controller中从Liferay搜索容器访问分页信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:45