Example usage for org.springframework.beans BeanWrapperImpl setPropertyValues

List of usage examples for org.springframework.beans BeanWrapperImpl setPropertyValues

Introduction

In this page you can find the example usage for org.springframework.beans BeanWrapperImpl setPropertyValues.

Prototype

@Override
    public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean ignoreInvalid)
            throws BeansException 

Source Link

Usage

From source file:org.wallride.web.controller.admin.user.UserDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model) {
    User user = userService.getUserById(id);
    if (user == null) {
        throw new HttpNotFoundException();
    }/*from   w  w  w.  j a  v  a2s  .com*/

    MutablePropertyValues mpvs = new MutablePropertyValues(
            UriComponentsBuilder.newInstance().query(query).build().getQueryParams());
    for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) {
        PropertyValue pv = i.next();
        boolean hasValue = false;
        for (String value : (List<String>) pv.getValue()) {
            if (StringUtils.hasText(value)) {
                hasValue = true;
                break;
            }
        }
        if (!hasValue) {
            i.remove();
        }
    }
    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new UserSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    UserSearchForm form = (UserSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = userService.getUserIds(form.toUserSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(user.getId());
        if (index < ids.size() - 1) {
            Long next = ids.get(index + 1);
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Long prev = ids.get(index - 1);
            model.addAttribute("prev", prev);
        }
    }

    model.addAttribute("user", user);
    model.addAttribute("query", query);
    return "user/describe";
}

From source file:org.wallride.web.controller.admin.page.PageDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Page page = pageService.getPageById(id);
    if (page == null) {
        throw new HttpNotFoundException();
    }// w  ww.  j a v a2 s .c  o  m

    if (!page.getLanguage().equals(language)) {
        Page target = pageService.getPageByCode(page.getCode(), language);
        if (target != null) {
            redirectAttributes.addAttribute("id", target.getId());
            return "redirect:/_admin/{language}/pages/describe?id={id}";
        } else {
            redirectAttributes.addFlashAttribute("original", page);
            redirectAttributes.addAttribute("code", page.getCode());
            return "redirect:/_admin/{language}/pages/create?code={code}";
        }
    }

    MutablePropertyValues mpvs = new MutablePropertyValues(
            UriComponentsBuilder.newInstance().query(query).build().getQueryParams());
    for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) {
        PropertyValue pv = i.next();
        boolean hasValue = false;
        for (String value : (List<String>) pv.getValue()) {
            if (StringUtils.hasText(value)) {
                hasValue = true;
                break;
            }
        }
        if (!hasValue) {
            i.remove();
        }
    }
    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new PageSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    PageSearchForm form = (PageSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = pageService.getPageIds(form.toPageSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(page.getId());
        if (index < ids.size() - 1) {
            Long next = ids.get(index + 1);
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Long prev = ids.get(index - 1);
            model.addAttribute("prev", prev);
        }
    }

    model.addAttribute("page", page);
    model.addAttribute("query", query);
    return "page/describe";
}

From source file:org.wallride.web.controller.admin.article.ArticleDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Article article = articleService.getArticleById(id);
    if (article == null) {
        throw new HttpNotFoundException();
    }/*w  w w.j av a2s .co m*/

    if (!article.getLanguage().equals(language)) {
        Article target = articleService.getArticleByCode(article.getCode(), language);
        if (target != null) {
            redirectAttributes.addAttribute("id", target.getId());
            return "redirect:/_admin/{language}/articles/describe?id={id}";
        } else {
            redirectAttributes.addFlashAttribute("original", article);
            redirectAttributes.addAttribute("code", article.getCode());
            return "redirect:/_admin/{language}/articles/create?code={code}";
        }
    }

    MutablePropertyValues mpvs = new MutablePropertyValues(
            UriComponentsBuilder.newInstance().query(query).build().getQueryParams());
    for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) {
        PropertyValue pv = i.next();
        boolean hasValue = false;
        for (String value : (List<String>) pv.getValue()) {
            if (StringUtils.hasText(value)) {
                hasValue = true;
                break;
            }
        }
        if (!hasValue) {
            i.remove();
        }
    }
    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new ArticleSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    ArticleSearchForm form = (ArticleSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = articleService.getArticleIds(form.toArticleSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(article.getId());
        if (index < ids.size() - 1) {
            Long next = ids.get(index + 1);
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Long prev = ids.get(index - 1);
            model.addAttribute("prev", prev);
        }
    }

    model.addAttribute("article", article);
    model.addAttribute("query", query);
    return "article/describe";
}