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

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

Introduction

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

Prototype

public void previousPage() 

Source Link

Document

Switch to previous page.

Usage

From source file:org.hoteia.qalingo.web.mvc.controller.search.CatalogSearchController.java

@RequestMapping(value = FoUrls.CATALOG_SEARCH_URL, method = RequestMethod.GET)
public ModelAndView search(final HttpServletRequest request, final Model model, @Valid SearchForm searchForm)
        throws Exception {
    ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request),
            FoUrls.CATALOG_SEARCH.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);
    final MarketArea marketArea = requestData.getMarketArea();

    // SANITY CHECK
    List<String> evictValues = new ArrayList<String>();
    evictValues.add("*");
    if (StringUtils.isNotEmpty(searchForm.getText()) && evictValues.contains(searchForm.getText())) {
        return displaySearch(request, model);
    }/*from  w w  w.j  ava2s  .c  om*/

    if (StringUtils.isEmpty(searchForm.getText()) && searchForm.getPage() == 0) {
        return displaySearch(request, model);
    }

    String sessionKeyPagedListHolder = "Search_ProductMarketing_PagedListHolder_"
            + request.getSession().getId();
    String sessionKeyFacet = "Search_ProductMarketing_Facet_" + request.getSession().getId();

    int page = 0;
    try {
        page = Integer.parseInt(request.getParameter("page"));
    } catch (Exception e) {
        // NO NEED
    }

    String mode = request.getParameter(Constants.PAGE_VIEW_MODE);
    String sortBy = searchForm.getSortBy();
    String order = searchForm.getOrder();
    int pageSize = searchForm.getPageSize();

    final List<String> facetFields = new ArrayList<String>();
    facetFields.add(ProductMarketingResponseBean.PRODUCT_MARKETING_SEARCH_FIELD_CATEGORIE_CODES);
    facetFields.add(ProductMarketingResponseBean.PRODUCT_MARKETING_SEARCH_FIELD_PRODUCT_BRAND_CODE);
    facetFields.add(ProductMarketingResponseBean.PRODUCT_MARKETING_SEARCH_FIELD_OPTION_DEFINITION_CODES);
    facetFields.add(ProductMarketingResponseBean.PRODUCT_MARKETING_SEARCH_FIELD_TAG_CODES);

    try {
        PagedListHolder<ProductMarketingViewBean> pagedListHolder;
        if (page == 0 || request.getSession().getAttribute(sessionKeyPagedListHolder) == null) {
            ProductMarketingResponseBean productMarketingResponseBean = null;

            String querySearch = getSearchQuery(marketArea, searchForm.getText());

            if (searchForm.getPrice() != null) {
                //                   if(searchForm.getCatalogCategoryList() != null){
                //                       productMarketingResponseBean = productMarketingSolrService.searchProductMarketing(querySearch, facetFields, searchForm.getPrice().getStartValue(), searchForm.getPrice().getEndValue(), 
                //                               searchForm.getCatalogCategoryList());
                //                   } else {
                //                       productMarketingResponseBean = productMarketingSolrService.searchProductMarketing(querySearch, facetFields, searchForm.getPrice().getStartValue(), searchForm.getPrice().getEndValue());
                //                   }
                productMarketingResponseBean = productMarketingSolrService.searchProductMarketing(querySearch,
                        facetFields, null);

            } else {
                productMarketingResponseBean = productMarketingSolrService.searchProductMarketing(querySearch,
                        facetFields, null);
            }

            pagedListHolder = initList(requestData, sessionKeyPagedListHolder, productMarketingResponseBean,
                    pageSize, sortBy, order);

            // FACETS
            List<SearchFacetViewBean> facets = frontofficeViewBeanFactory
                    .buildListViewBeanCatalogSearchFacet(requestData, productMarketingResponseBean);
            modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
            request.getSession().setAttribute(sessionKeyFacet, facets);

        } else {
            pagedListHolder = (PagedListHolder<ProductMarketingViewBean>) request.getSession()
                    .getAttribute(sessionKeyPagedListHolder);

            // FACETS
            List<SearchFacetViewBean> facets = (List<SearchFacetViewBean>) request.getSession()
                    .getAttribute(sessionKeyFacet);
            modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
        }

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

        modelAndView.addObject(Constants.PAGINATION_PAGE_URL, requestUtil.getCurrentRequestUrl(request));
        modelAndView.addObject(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, pagedListHolder);
        modelAndView.addObject(Constants.SEARCH_TEXT, searchForm.getText());
        modelAndView.addObject(Constants.PAGINATION_PAGE_SIZE, pagedListHolder.getPageSize());
        modelAndView.addObject(Constants.PAGINATION_SORT_BY, sortBy);
        modelAndView.addObject(Constants.PAGINATION_ORDER, order);
        modelAndView.addObject(Constants.PRICE_RANGE_PARAMETER, searchForm.getPrice());
        //         modelAndView.addObject(Constants.CATALOG_CATEGORIES_PARAMETER, searchForm.getCategoriesFilter());

    } catch (Exception e) {
        logger.error("SOLR Error", e);
        return displaySearch(request, model);
    }

    loadRecentProducts(requestData, model);

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

    overrideDefaultPageTitle(request, modelAndView, FoUrls.CATALOG_SEARCH.getKey());

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

    return modelAndView;
}

From source file:org.hoteia.qalingo.web.mvc.controller.search.SearchController.java

@RequestMapping(value = BoUrls.SEARCH_URL, method = RequestMethod.POST)
public ModelAndView search(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception {
    ModelAndViewThemeDevice modelAndView = new ModelAndViewThemeDevice(getCurrentVelocityPath(request),
            BoUrls.SEARCH.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);

    String searchText = request.getParameter("search-text");
    String url = request.getRequestURI();
    String page = request.getParameter(Constants.PAGINATION_PAGE_PARAMETER);
    String sessionKey = "PagedListHolder_Shippings";

    PagedListHolder<GlobalSearchViewBean> globalSearchViewBeanPagedListHolder = new PagedListHolder<GlobalSearchViewBean>();

    if (StringUtils.isEmpty(page)) {
        globalSearchViewBeanPagedListHolder = initList(request, sessionKey, searchText);

    } else {//  ww  w. j a v a  2  s  .  c o m
        globalSearchViewBeanPagedListHolder = (PagedListHolder) request.getSession().getAttribute(sessionKey);
        if (globalSearchViewBeanPagedListHolder == null) {
            globalSearchViewBeanPagedListHolder = initList(request, sessionKey, searchText);
        }
        int pageTarget = new Integer(page).intValue() - 1;
        int pageCurrent = globalSearchViewBeanPagedListHolder.getPage();
        if (pageCurrent < pageTarget) {
            for (int i = pageCurrent; i < pageTarget; i++) {
                globalSearchViewBeanPagedListHolder.nextPage();
            }
        } else if (pageCurrent > pageTarget) {
            for (int i = pageTarget; i < pageCurrent; i++) {
                globalSearchViewBeanPagedListHolder.previousPage();
            }
        }
    }
    modelAndView.addObject(Constants.PAGINATION_PAGE_URL, url);
    modelAndView.addObject(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, globalSearchViewBeanPagedListHolder);

    return modelAndView;
}

From source file:org.hoteia.qalingo.web.mvc.controller.search.StoreSearchController.java

@RequestMapping(value = FoUrls.STORE_SEARCH_URL, method = RequestMethod.GET)
public ModelAndView search(final HttpServletRequest request, final Model model, @Valid SearchForm searchForm)
        throws Exception {
    ModelAndViewThemeDevice modelAndView = (ModelAndViewThemeDevice) displaySearch(request, model);
    final RequestData requestData = requestUtil.getRequestData(request);

    // SANITY CHECK : evict values
    List<String> evictValues = new ArrayList<String>();
    evictValues.add("*");
    if (StringUtils.isNotEmpty(searchForm.getText()) && evictValues.contains(searchForm.getText())) {
        return modelAndView;
    }//ww w . java  2  s .c  om

    // SANITY CHECK : if empty search : use geolocated city as default value
    if (StringUtils.isEmpty(searchForm.getText()) && searchForm.getPage() == 0
            && requestData.getGeolocData() != null && requestData.getGeolocData().getCity() != null) {
        searchForm.setText(requestData.getGeolocData().getCity().getName());
    }

    // SANITY CHECK : empty search
    if (StringUtils.isEmpty(searchForm.getText()) && searchForm.getPage() == 0) {
        return modelAndView;
    }

    String url = requestUtil.getCurrentRequestUrl(request);

    String sessionKeyPagedListHolder = "Search_Store_PagedListHolder_" + request.getSession().getId();
    String sessionKeyFacet = "Search_Store_Facet_" + request.getSession().getId();

    int page = 0;
    try {
        page = Integer.parseInt(request.getParameter("page"));
    } catch (Exception e) {
        // NO NEED
    }

    String mode = request.getParameter(Constants.PAGE_VIEW_MODE);
    String cities = request.getParameter("cities");
    String countries = request.getParameter("countries");

    List<String> cityList = new ArrayList<String>();
    if (StringUtils.isEmpty(cities)) {
        cityList = null;
    } else {
        String[] arr = cities.split(",");
        cityList = Arrays.asList(arr);
    }
    List<String> countryList = new ArrayList<String>();
    if (StringUtils.isEmpty(countries)) {
        countryList = null;
    } else {
        String[] arr = countries.split(",");
        countryList = Arrays.asList(arr);
    }

    int pageSize = searchForm.getPageSize();
    if (pageSize == 0) {
        pageSize = 16;
    }
    String sortBy = searchForm.getSortBy();
    String order = searchForm.getOrder();

    try {
        PagedListHolder<StoreViewBean> pagedListHolder;
        if (page == 0 || request.getSession().getAttribute(sessionKeyPagedListHolder) == null) {
            StoreResponseBean storeResponseBean = null;

            List<String> facetFields = new ArrayList<String>();
            facetFields.add(StoreResponseBean.STORE_CITY_FACET_FIELD);
            facetFields.add(StoreResponseBean.STORE_COUNTRY_FACET_FIELD);

            String query = getSearchQuery(searchForm.getText());

            SolrParam solrParam = new SolrParam();
            solrParam.put("rows", "150");

            storeResponseBean = storeSolrService.searchStore(query, facetFields, cityList, countryList,
                    solrParam);
            //               StoreResponseBean storeResponBeanNonFilter = storeSolrService.searchStore(, , facetFields);
            pagedListHolder = initList(requestData, sessionKeyPagedListHolder, storeResponseBean, pageSize,
                    sortBy, order);

            // FACETS
            //                List<SearchFacetViewBean> facets = frontofficeViewBeanFactory.buildListViewBeanStoreSearchFacet(requestData, storeResponBeanNonFilter);
            List<SearchFacetViewBean> facets = frontofficeViewBeanFactory
                    .buildListViewBeanStoreSearchFacet(requestData, storeResponseBean);
            modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
            request.getSession().setAttribute(sessionKeyFacet, facets);

        } else {
            pagedListHolder = (PagedListHolder<StoreViewBean>) request.getSession()
                    .getAttribute(sessionKeyPagedListHolder);

            // FACETS
            List<SearchFacetViewBean> facets = (List<SearchFacetViewBean>) request.getSession()
                    .getAttribute(sessionKeyFacet);
            modelAndView.addObject(AbstractSolrService.SEARCH_FACET_FIELD_LIST, facets);
        }

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

        modelAndView.addObject(Constants.PAGINATION_PAGE_URL, url);
        modelAndView.addObject(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, pagedListHolder);
        modelAndView.addObject(Constants.SEARCH_TEXT, searchForm.getText());
        modelAndView.addObject(Constants.PAGINATION_PAGE_SIZE, pagedListHolder.getPageSize());
        modelAndView.addObject(Constants.PAGINATION_SORT_BY, sortBy);
        modelAndView.addObject(Constants.PAGINATION_ORDER, order);
        modelAndView.addObject(Constants.STORE_CITY_PARAMETER, cities);
        modelAndView.addObject(Constants.STORE_COUNTRY_PARAMETER, countries);

    } catch (Exception e) {
        logger.error("SOLR Error", e);
        return modelAndView;
    }

    modelAndView.addObject("storeSearchUrl", urlService.generateUrl(FoUrls.STORE_SEARCH, requestData));

    return modelAndView;
}

From source file:org.hoteia.qalingo.web.mvc.controller.store.StoreController.java

private void displayList(final HttpServletRequest request, final Model model, final RequestData requestData,
        List<Store> stores) throws Exception {
    String url = request.getRequestURI();
    String page = request.getParameter(Constants.PAGINATION_PAGE_PARAMETER);
    String sessionKey = "PagedListHolder_Stores";

    PagedListHolder<StoreViewBean> storeViewBeanPagedListHolder = new PagedListHolder<StoreViewBean>();

    if (stores == null) {
        final String retailerCode = request.getParameter(RequestConstants.REQUEST_PARAMETER_RETAILER_CODE);
        stores = retailerService.findStoresByRetailerCode(retailerCode,
                FetchPlanGraphRetailer.fullStoreFetchPlan());
    }//from w w  w .j  a  va  2  s  . co m

    if (StringUtils.isEmpty(page)) {
        storeViewBeanPagedListHolder = initList(request, sessionKey, requestData, stores);

    } else {
        storeViewBeanPagedListHolder = (PagedListHolder) request.getSession().getAttribute(sessionKey);
        if (storeViewBeanPagedListHolder == null) {
            storeViewBeanPagedListHolder = initList(request, sessionKey, requestData, stores);
        }
        int pageTarget = new Integer(page).intValue() - 1;
        int pageCurrent = storeViewBeanPagedListHolder.getPage();
        if (pageCurrent < pageTarget) {
            for (int i = pageCurrent; i < pageTarget; i++) {
                storeViewBeanPagedListHolder.nextPage();
            }
        } else if (pageCurrent > pageTarget) {
            for (int i = pageTarget; i < pageCurrent; i++) {
                storeViewBeanPagedListHolder.previousPage();
            }
        }
    }
    model.addAttribute(Constants.PAGINATION_PAGE_URL, url);
    model.addAttribute(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, storeViewBeanPagedListHolder);
}

From source file:org.hoteia.qalingo.web.mvc.controller.tax.TaxController.java

protected void displayList(final HttpServletRequest request, final Model model, final RequestData requestData)
        throws Exception {
    String url = request.getRequestURI();
    String page = request.getParameter(Constants.PAGINATION_PAGE_PARAMETER);
    String sessionKey = "PagedListHolder_Taxes";

    PagedListHolder<TaxViewBean> taxViewBeanPagedListHolder = new PagedListHolder<TaxViewBean>();

    if (StringUtils.isEmpty(page)) {
        taxViewBeanPagedListHolder = initList(request, sessionKey, requestData);

    } else {/*  w  w  w  .  j  a v  a  2 s  .co  m*/
        taxViewBeanPagedListHolder = (PagedListHolder) request.getSession().getAttribute(sessionKey);
        if (taxViewBeanPagedListHolder == null) {
            taxViewBeanPagedListHolder = initList(request, sessionKey, requestData);
        }
        int pageTarget = new Integer(page).intValue() - 1;
        int pageCurrent = taxViewBeanPagedListHolder.getPage();
        if (pageCurrent < pageTarget) {
            for (int i = pageCurrent; i < pageTarget; i++) {
                taxViewBeanPagedListHolder.nextPage();
            }
        } else if (pageCurrent > pageTarget) {
            for (int i = pageTarget; i < pageCurrent; i++) {
                taxViewBeanPagedListHolder.previousPage();
            }
        }
    }
    model.addAttribute(Constants.PAGINATION_PAGE_URL, url);
    model.addAttribute(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, taxViewBeanPagedListHolder);
}

From source file:org.hoteia.qalingo.web.mvc.controller.user.UserController.java

protected void displayList(final HttpServletRequest request, final Model model, final RequestData requestData)
        throws Exception {
    String url = request.getRequestURI();
    String page = request.getParameter(Constants.PAGINATION_PAGE_PARAMETER);
    String sessionKey = "PagedListHolder_Users";

    PagedListHolder<UserViewBean> userViewBeanPagedListHolder = new PagedListHolder<UserViewBean>();

    if (StringUtils.isEmpty(page)) {
        userViewBeanPagedListHolder = initList(request, sessionKey, requestData);

    } else {/* w  w  w .  ja va 2s  .  com*/
        userViewBeanPagedListHolder = (PagedListHolder) request.getSession().getAttribute(sessionKey);
        if (userViewBeanPagedListHolder == null) {
            userViewBeanPagedListHolder = initList(request, sessionKey, requestData);
        }
        int pageTarget = new Integer(page).intValue() - 1;
        int pageCurrent = userViewBeanPagedListHolder.getPage();
        if (pageCurrent < pageTarget) {
            for (int i = pageCurrent; i < pageTarget; i++) {
                userViewBeanPagedListHolder.nextPage();
            }
        } else if (pageCurrent > pageTarget) {
            for (int i = pageTarget; i < pageCurrent; i++) {
                userViewBeanPagedListHolder.previousPage();
            }
        }
    }
    model.addAttribute(Constants.PAGINATION_PAGE_URL, url);
    model.addAttribute(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, userViewBeanPagedListHolder);
}

From source file:org.hoteia.qalingo.web.mvc.controller.warehouse.WarehouseController.java

protected void displayList(final HttpServletRequest request, final Model model, final RequestData requestData)
        throws Exception {
    String url = request.getRequestURI();
    String page = request.getParameter(Constants.PAGINATION_PAGE_PARAMETER);
    String sessionKey = "PagedListHolder_Warehouses";

    PagedListHolder<WarehouseViewBean> warehouseViewBeanPagedListHolder = new PagedListHolder<WarehouseViewBean>();

    if (StringUtils.isEmpty(page)) {
        warehouseViewBeanPagedListHolder = initList(request, sessionKey, requestData);

    } else {/*from   www  . j  a v a  2  s . com*/
        warehouseViewBeanPagedListHolder = (PagedListHolder) request.getSession().getAttribute(sessionKey);
        if (warehouseViewBeanPagedListHolder == null) {
            warehouseViewBeanPagedListHolder = initList(request, sessionKey, requestData);
        }
        int pageTarget = new Integer(page).intValue() - 1;
        int pageCurrent = warehouseViewBeanPagedListHolder.getPage();
        if (pageCurrent < pageTarget) {
            for (int i = pageCurrent; i < pageTarget; i++) {
                warehouseViewBeanPagedListHolder.nextPage();
            }
        } else if (pageCurrent > pageTarget) {
            for (int i = pageTarget; i < pageCurrent; i++) {
                warehouseViewBeanPagedListHolder.previousPage();
            }
        }
    }
    model.addAttribute(Constants.PAGINATION_PAGE_URL, url);
    model.addAttribute(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, warehouseViewBeanPagedListHolder);
}

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

/**
 * Deal with the URIs "/control/joinRequestList"
 * get the join requests list(paging and sorting)
 */// w w  w.j ava2  s.c om
@RequestMapping(value = Routes.JOIN_REQUEST_LIST_URL)
public String joinRequestList(HttpServletRequest request,
        @RequestParam(value = "page", required = false) String page) {
    PagedListHolder pagedListHolder;

    if (page == null || "".equals(page)) {
        pagedListHolder = getPageListData(false);
    } else {

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

        if ("prev".equals(page)) {
            if (pagedListHolder != null) {
                pagedListHolder.previousPage();
            } else {
                pagedListHolder = getPageListData(null);
            }
        } else if ("next".equals(page)) {
            if (pagedListHolder != null) {
                pagedListHolder.nextPage();
            } else {
                pagedListHolder = getPageListData(null);
            }
        } else if ("all".equals(page)) {
            pagedListHolder = getPageListData(null);
        } else if ("incomplete".equals(page)) {
            pagedListHolder = getPageListData(false);
        } else if ("complete".equals(page)) {
            pagedListHolder = getPageListData(true);
        } else if ("sort".equals(page)) {
            String property = (String) request.getParameter("property");
            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();
        }
    }
    pagedListHolder.setPageSize(pageSize);
    request.getSession().setAttribute("joinRequests", pagedListHolder);
    request.setAttribute("specialty", getSpecialtyContext());

    if (pagedListHolder.isFirstPage()) {
        request.setAttribute("firstPage", true);
    }

    if (pagedListHolder.isLastPage()) {
        request.setAttribute("lastPage", true);
    }
    List<JoinRequest> joinRequestList = LegacySpringUtils.getJoinRequestManager().getUsersJoinRequests(false);
    if (joinRequestList != null && joinRequestList.size() > 0) {
        request.setAttribute("inCompletedNumber", joinRequestList.size());
    }
    return forwardTo(request, Routes.JOIN_REQUEST_LIST_PAGE);
}

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";
        }/*  w  w w .  j  a v a 2 s  .  com*/

        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);
}

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

@RequestMapping(value = Routes.UNIT_USERS_LIST_URL)
public String getUsers(@RequestParam(value = "unitcode", required = false) String unitcode,
        @RequestParam(value = "page", required = false) String page,
        @RequestParam(value = "property", required = false) String property, HttpServletRequest request) {
    if (StringUtils.isNotEmpty(unitcode)) {
        Unit unit = LegacySpringUtils.getUnitManager().get(unitcode);
        request.setAttribute("unit", unit);
    }//  w w w . ja va2 s  . c om

    PagedListHolder pagedListHolder = (PagedListHolder) request.getSession().getAttribute("unitUsers");
    if (StringUtils.isEmpty(page) || pagedListHolder == null) {
        List unitUsers = null;
        if (StringUtils.isEmpty(unitcode)) {
            unitUsers = LegacySpringUtils.getUnitManager().getAllUnitUsers();
        } else {
            unitUsers = LegacySpringUtils.getUnitManager().getUnitUsers(unitcode);
        }
        pagedListHolder = new PagedListHolder(unitUsers);
        request.getSession().setAttribute("unitUsers", pagedListHolder);
    } else {
        if ("prev".equals(page)) {
            pagedListHolder.previousPage();
        } else if ("next".equals(page)) {
            pagedListHolder.nextPage();
        } 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();
        }
    }

    return forwardTo(request, Routes.UNIT_USERS_LIST_PAGE);
}