Example usage for org.springframework.beans.support PagedListHolder getPageList

List of usage examples for org.springframework.beans.support PagedListHolder getPageList

Introduction

In this page you can find the example usage for org.springframework.beans.support PagedListHolder getPageList.

Prototype

public List<E> getPageList() 

Source Link

Document

Return a sub-list representing the current page.

Usage

From source file:sample.tomcat.jsp.MessageController.java

@RequestMapping(value = "/list", method = RequestMethod.GET)
public ModelAndView showList(@RequestParam(required = false) Integer page,
        @RequestParam(required = false) Integer maxItems, @ModelAttribute("research") Research research) {
    ModelAndView modelAndView = new ModelAndView("list");
    List<Message> messageList = messageService.findAll();
    PagedListHolder<Message> pagedListHolder = new PagedListHolder<>(messageList);
    modelAndView.addObject("maxItems", pagedListHolder.getPageSize());
    modelAndView.addObject("maxPages", pagedListHolder.getPageCount());
    if (maxItems == null || maxItems < 1 || maxItems > pagedListHolder.getPageSize()) {
        pagedListHolder.setPageSize(DEFAULT_PAGE_SIZE);
    } else {/*from  w ww  . jav  a  2  s .c o  m*/
        pagedListHolder.setPageSize(maxItems);
    }
    if (page == null || page < 1 || page > pagedListHolder.getPageCount())
        page = 1;
    modelAndView.addObject("page", page);
    if (page == null || page < 1 || page > pagedListHolder.getPageCount()) {
        pagedListHolder.setPage(0);
        modelAndView.addObject("messageList", pagedListHolder.getPageList());
    } else if (page <= pagedListHolder.getPageCount()) {
        pagedListHolder.setPage(page - 1);
        modelAndView.addObject("messageList", pagedListHolder.getPageList());
    }

    return modelAndView;
}

From source file:sample.tomcat.jsp.MessageController.java

@RequestMapping(value = "/search", method = RequestMethod.GET)
public ModelAndView showSearch(HttpServletRequest request,
        @RequestParam(value = "name", required = true) String name,
        @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer maxItems,
        @ModelAttribute("research") Research research) {
    ModelAndView modelAndView = new ModelAndView("search");
    name = request.getParameter("name");
    List<Message> messageSearch = messageService.findByFirstNameContainsOrLastNameContainsAllIgnoreCase(name,
            name);/*from   w  ww  .j a v a  2  s .co  m*/
    PagedListHolder<Message> pagedListHolder = new PagedListHolder<>(messageSearch);
    // pagedListHolder.setPageSize(maxItems);
    modelAndView.addObject("maxItems", pagedListHolder.getPageSize());
    modelAndView.addObject("maxPages", pagedListHolder.getPageCount());
    if (maxItems == null || maxItems < 1 || maxItems > pagedListHolder.getPageSize()) {
        pagedListHolder.setPageSize(DEFAULT_PAGE_SIZE);
    } else {
        pagedListHolder.setPageSize(maxItems);
    }

    if (page == null || page < 1 || page > pagedListHolder.getPageCount())
        page = 1;
    modelAndView.addObject("page", page);
    if (page == null || page < 1 || page > pagedListHolder.getPageCount()) {
        pagedListHolder.setPage(0);
        modelAndView.addObject("messageSearch", pagedListHolder.getPageList());
    } else if (page <= pagedListHolder.getPageCount()) {
        pagedListHolder.setPage(page - 1);
        modelAndView.addObject("messageSearch", pagedListHolder.getPageList());
    }

    return modelAndView;
}

From source file:org.hoteia.qalingo.web.mvc.controller.catalog.ProductLineController.java

@RequestMapping(FoUrls.CATEGORY_AS_LINE_URL)
public ModelAndView productLine(final HttpServletRequest request, final Model model,
        @PathVariable(RequestConstants.URL_PATTERN_CATEGORY_CODE) final String categoryCode,
        final SearchForm searchForm) throws Exception {
    ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request),
            FoUrls.CATEGORY_AS_LINE.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);
    final Cart currentCart = requestData.getCart();

    final CatalogCategoryVirtual catalogCategory = catalogCategoryService.getVirtualCatalogCategoryByCode(
            categoryCode, requestData.getVirtualCatalogCode(), requestData.getMasterCatalogCode(),
            new FetchPlan(categoryVirtualFetchPlans));

    if (catalogCategory != null) {
        final CatalogCategoryViewBean catalogCategoryViewBean = frontofficeViewBeanFactory
                .buildViewBeanVirtualCatalogCategory(requestUtil.getRequestData(request), catalogCategory);

        String sortBy = request.getParameter("sortBy");
        String orderBy = request.getParameter("orderBy");
        String pageSizeParameter = request.getParameter("pageSize");
        String pageParameter = request.getParameter("page");
        String mode = request.getParameter("mode");

        int page = NumberUtils.toInt(pageParameter, 1) - 1;
        int pageSize = NumberUtils.toInt(pageSizeParameter, 9);

        List<ProductMarketingViewBean> productMarketings = catalogCategoryViewBean.getProductMarketings();
        PagedListHolder<ProductMarketingViewBean> productList = new PagedListHolder<ProductMarketingViewBean>(
                productMarketings);//from   w  w  w  .j ava2s  .  c  o  m
        productList.setPageSize(pageSize);
        productList.setPage(page);

        int pageCurrent = productList.getPage();
        if (pageCurrent < page) {
            for (int i = pageCurrent; i < page; i++) {
                productList.nextPage();
            }
        } else if (pageCurrent > page) {
            for (int i = page; i < pageCurrent; i++) {
                productList.previousPage();
            }
        }

        catalogCategoryViewBean.setProductMarketings(productList.getPageList());

        final CartViewBean cartViewBean = frontofficeViewBeanFactory
                .buildViewBeanCart(requestUtil.getRequestData(request), currentCart);
        modelAndView.addObject(ModelConstants.CART_VIEW_BEAN, cartViewBean);

        final CatalogBreadcrumbViewBean catalogBreadcrumbViewBean = frontofficeViewBeanFactory
                .buildViewBeanCatalogBreadcrumb(requestUtil.getRequestData(request), catalogCategory);
        model.addAttribute(ModelConstants.CATALOG_BREADCRUMB_VIEW_BEAN, catalogBreadcrumbViewBean);

        model.addAttribute(ModelConstants.CATALOG_CATEGORY_VIEW_BEAN, catalogCategoryViewBean);
        model.addAttribute("sortBy", sortBy);
        model.addAttribute("pageSize", pageSize);
        model.addAttribute("orderBy", orderBy);
        model.addAttribute("currentPage", page);
        model.addAttribute("mode", mode);
        model.addAttribute("totalPage", productList.getPageCount());

        loadRecentProducts(requestData, model);

        Object[] params = { catalogCategoryViewBean.getI18nName() };
        overrideDefaultPageTitle(request, modelAndView, FoUrls.CATEGORY_AS_LINE.getKey(), params);

        model.addAttribute(ModelConstants.BREADCRUMB_VIEW_BEAN,
                buildBreadcrumbViewBean(requestData, catalogCategory));

        model.addAttribute(ModelConstants.SEO_DATA_VIEW_BEAN, initSeo(request, catalogCategoryViewBean));

        model.addAttribute(ModelConstants.PRODUCT_BRANDS_VIEW_BEAN, brandList(request, model));

        return modelAndView;
    }
    final String urlRedirect = urlService.generateRedirectUrl(FoUrls.HOME, requestUtil.getRequestData(request));
    return new ModelAndView(new RedirectView(urlRedirect));
}