List of usage examples for org.springframework.web.servlet.support ServletUriComponentsBuilder fromRequest
public static ServletUriComponentsBuilder fromRequest(HttpServletRequest request)
From source file:org.wallride.web.support.Pagination.java
public Pagination(Page<T> page, HttpServletRequest request) { this.page = page; this.url = ServletUriComponentsBuilder.fromRequest(request).replaceQueryParam("page").build().toUriString(); }
From source file:com.microservice.training.hal.HalBrowser.java
/** * Returns the View to redirect to to access the HAL browser. * /*from w w w. j a va 2 s . co m*/ * @param request must not be {@literal null}. * @param browserRelative * @return */ private View getRedirectView(HttpServletRequest request, boolean browserRelative) { ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequest(request); UriComponents components = builder.build(); String path = components.getPath() == null ? "" : components.getPath(); if (!browserRelative) { builder.path(BROWSER); } builder.path(INDEX); builder.fragment(browserRelative ? path.substring(0, path.lastIndexOf("/browser")) : path); return new RedirectView(builder.build().toUriString()); }
From source file:org.wallride.web.controller.admin.customfield.CustomFieldSearchController.java
@RequestMapping(method = RequestMethod.GET) public String search(@PathVariable String language, @Validated @ModelAttribute("form") CustomFieldSearchForm form, BindingResult result, @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException { Page<CustomField> customFields = customfieldService.getCustomFields(form.toCustomFieldSearchRequest(), pageable);/*from w w w . java 2 s. c o m*/ model.addAttribute("customFields", customFields); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new Pagination<>(customFields, servletRequest)); UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest) .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build(); if (!StringUtils.isEmpty(uriComponents.getQuery())) { model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8")); } return "customfield/index"; }
From source file:org.wallride.web.controller.admin.comment.CommentSearchController.java
@RequestMapping(method = RequestMethod.GET) public String search(@PathVariable String language, @Validated CommentSearchForm form, BindingResult result, @PageableDefault(value = 50, sort = "date", direction = Sort.Direction.DESC) Pageable pageable, Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException { Page<Comment> comments = commentService.getComments(form.toCommentSearchRequest(), pageable); model.addAttribute("form", form); model.addAttribute("comments", comments); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new org.wallride.web.support.Pagination<>(comments, servletRequest)); UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest) .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build(); if (!StringUtils.isEmpty(uriComponents.getQuery())) { model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8")); }/*from w w w . j av a 2 s . c o m*/ return "comment/index"; }
From source file:org.wallride.web.controller.admin.user.UserSearchController.java
@RequestMapping(method = RequestMethod.GET) public String search(@PathVariable String language, @Validated @ModelAttribute("form") UserSearchForm form, BindingResult result, @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException { Page<User> users = userService.getUsers(form.toUserSearchRequest(), pageable); model.addAttribute("users", users); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new Pagination<>(users, servletRequest)); UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest) .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build(); if (!StringUtils.isEmpty(uriComponents.getQuery())) { model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8")); }//ww w . ja v a 2s.c o m return "user/index"; }
From source file:org.wallride.web.controller.admin.tag.TagSearchController.java
@RequestMapping public String search(@PathVariable String language, @Validated @ModelAttribute("form") TagSearchForm form, BindingResult errors, @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException { Page<Tag> tags = tagService.getTags(form.toTagSearchRequest(), pageable); model.addAttribute("tags", tags); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new Pagination<>(tags, servletRequest)); UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest) .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build(); if (!StringUtils.isEmpty(uriComponents.getQuery())) { model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8")); }//w ww . ja v a 2 s .c om return "tag/index"; }
From source file:org.wallride.web.controller.admin.page.PageSearchController.java
@RequestMapping(method = RequestMethod.GET) public String search(@PathVariable String language, @Validated @ModelAttribute("form") PageSearchForm form, BindingResult result, @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException { org.springframework.data.domain.Page<Page> pages = pageService.getPages(form.toPageSearchRequest(), pageable);/*from w w w . j a va2 s . c o m*/ model.addAttribute("pages", pages); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new Pagination<>(pages, servletRequest)); UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest) .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build(); if (!StringUtils.isEmpty(uriComponents.getQuery())) { model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8")); } return "page/index"; }
From source file:org.wallride.web.controller.admin.article.ArticleSearchController.java
@RequestMapping(method = RequestMethod.GET) public String search(@PathVariable String language, @Validated @ModelAttribute("form") ArticleSearchForm form, BindingResult result, @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException { Page<Article> articles = articleService.getArticles(form.toArticleSearchRequest(), pageable); model.addAttribute("articles", articles); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new Pagination<>(articles, servletRequest)); UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest) .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build(); if (!StringUtils.isEmpty(uriComponents.getQuery())) { model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8")); }/* w ww. j a va2 s .c o m*/ return "article/index"; }
From source file:org.meruvian.yama.webapp.interceptor.OAuth2ClientContextInterceptor.java
/** * Calculate the current URI given the request. * // w w w . j a va2 s.c om * @param request The request. * @return The current uri. */ protected String calculateCurrentUri(HttpServletRequest request) throws UnsupportedEncodingException { ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequest(request); // Now work around SPR-10172... String queryString = request.getQueryString(); boolean legalSpaces = queryString != null && queryString.contains("+"); if (legalSpaces) { builder.replaceQuery(queryString.replace("+", "%20")); } UriComponents uri = null; try { uri = builder.replaceQueryParam("code").build(true); } catch (IllegalArgumentException ex) { // ignore failures to parse the url (including query string). does't make sense // for redirection purposes anyway. return null; } String query = uri.getQuery(); if (legalSpaces) { query = query.replace("%20", "+"); } return ServletUriComponentsBuilder.fromUri(uri.toUri()).replaceQuery(query).build().toString(); }