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

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

Introduction

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

Prototype

public int getPage() 

Source Link

Document

Return the current page number.

Usage

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 {//from ww  w .j  a v a 2 s  . c  om
        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;
    }/*from  w ww. j  av a 2  s  . c  o m*/

    // 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 ww .  j a v a2 s  .  com

    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 {/*from   w w  w  .j  a va 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 {//  ww w.  ja va 2 s .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 {/*w w w .  j  av  a2s . c o m*/
        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);
}