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

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

Introduction

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

Prototype

public int getPageCount() 

Source Link

Document

Return the number of pages for the current source list.

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. j a  v  a2 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. ja v  a 2s .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.fenixedu.spaces.ui.services.OccupationService.java

public PagedListHolder<OccupationRequest> getBook(List<OccupationRequest> requests, String pageString) {
    PagedListHolder<OccupationRequest> book = new PagedListHolder<>(requests);
    book.setPageSize(30);/*from www.j  ava  2s. c o  m*/
    int page = 0;

    if (Strings.isNullOrEmpty(pageString)) {
        page = 0;
    } else {
        try {
            page = Integer.parseInt(pageString);
        } catch (NumberFormatException nfe) {
            if ("f".equals(pageString)) {
                page = 0;
            } else if ("l".equals(pageString)) {
                page = book.getPageCount();
            }
        }
    }
    book.setPage(page == 0 ? 0 : page - 1);
    return book;
}

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 ava2 s  . 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));
}

From source file:org.patientview.patientview.controller.UnitPatientsControlller.java

@RequestMapping(value = Routes.UNIT_PATIENTS_LIST_URL)
public String getPatients(@RequestParam(value = "unitcode", required = false) String unitcode,
        @RequestParam(value = "page", required = false) String page,
        @RequestParam(value = "nhsno", required = false) String nhsno,
        @RequestParam(value = "firstname", required = false) String firstname,
        @RequestParam(value = "lastname", required = false) String lastname,
        @RequestParam(value = "showgps", required = false) boolean showgps,
        @RequestParam(value = "property", required = false) String property, HttpServletRequest request) {

    unitcode = (unitcode == null) ? "" : unitcode;

    PagedListHolder pagedListHolder = (PagedListHolder) request.getSession().getAttribute("patients");

    //TODO So we get every patient in the database and then start paging
    //TODO There is probably not a single use case why you would want this many patients
    //TODO Pagination needs to restrict query results

    if (StringUtils.isEmpty(page) || pagedListHolder == null) {

        // Validation
        if (StringUtils.isEmpty(unitcode) && StringUtils.isEmpty(nhsno)
                && StringUtils.isEmpty(firstname + lastname)) {
            return "redirect:/renal/control/unitPatientsUnitSelect.do?validation=failed";
        }//  ww  w  .ja v  a2s .  c om

        nhsno = (nhsno == null) ? "" : nhsno;
        firstname = (firstname == null) ? "" : firstname;
        lastname = (lastname == null) ? "" : lastname;
        List patients = null;
        PatientManager patientManager = LegacySpringUtils.getPatientManager();
        if (StringUtils.isEmpty(unitcode)) {
            if (LegacySpringUtils.getSecurityUserManager().isRolePresent("superadmin")) {
                patients = patientManager.getAllUnitPatientsWithTreatmentIncludeHidden(nhsno, firstname,
                        lastname, showgps);
            } else {
                patients = patientManager.getAllUnitPatientsWithTreatment(nhsno, firstname, lastname, showgps);
            }
        } else {
            if (LegacySpringUtils.getSecurityUserManager().isRolePresent("superadmin")) {
                patients = patientManager.getUnitPatientsWithTreatmentIncludeHidden(unitcode, nhsno, firstname,
                        lastname, showgps);
            } else {
                patients = patientManager.getUnitPatientsWithTreatment(unitcode, nhsno, firstname, lastname,
                        showgps);
            }
        }
        pagedListHolder = new PagedListHolder(patients);
        request.getSession().setAttribute("patients", pagedListHolder);
    } else {
        if ("first".equals(page)) {
            pagedListHolder.setPage(0);
        } else if ("prev".equals(page)) {
            pagedListHolder.previousPage();
        } else if ("next".equals(page)) {
            pagedListHolder.nextPage();
        } else if ("last".equals(page)) {
            pagedListHolder.setPage(pagedListHolder.getPageCount() - 1);
        } else if ("sort".equals(page)) {
            MutableSortDefinition newSort = new MutableSortDefinition(property, true, false);
            SortDefinition sort = pagedListHolder.getSort();
            if (StringUtils.equals(sort.getProperty(), property)) {
                newSort.setAscending(!sort.isAscending());
            }
            pagedListHolder.setSort(newSort);
            pagedListHolder.resort();
        }
    }
    //Reset the unit selection on the first page
    if (page == null) {
        request.getSession().setAttribute("unit", null);
    }

    if (StringUtils.isNotEmpty(unitcode)) {
        Unit unit = LegacySpringUtils.getUnitManager().get(unitcode);
        request.getSession().setAttribute("unit", unit);
    }

    return forwardTo(request, Routes.UNIT_PATIENTS_LIST_PAGE);
}