Example usage for org.springframework.web.servlet.mvc.support RedirectAttributes addAttribute

List of usage examples for org.springframework.web.servlet.mvc.support RedirectAttributes addAttribute

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc.support RedirectAttributes addAttribute.

Prototype

@Override
    RedirectAttributes addAttribute(String attributeName, @Nullable Object attributeValue);

Source Link

Usage

From source file:org.wallride.web.controller.admin.tag.TagBulkDeleteController.java

@RequestMapping
public String delete(@Valid @ModelAttribute("form") TagBulkDeleteForm form, BindingResult errors, String query,
        AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) {
    redirectAttributes.addAttribute("query", query);

    if (!form.isConfirmed()) {
        errors.rejectValue("confirmed", "Confirmed");
    }//from  ww w. j a  v a  2  s . c  o m
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "redirect:/_admin/{language}/tags/index";
    }

    Collection<Tag> tags = null;
    try {
        tags = tagService.bulkDeleteTag(form.buildTagBulkDeleteRequest(), errors);
    } catch (ValidationException e) {
        if (errors.hasErrors()) {
            logger.debug("Errors: {}", errors);
            return "redirect:/_admin/{language}/tags/index";
        }
        throw e;
    }

    List<String> errorMessages = null;
    if (errors.hasErrors()) {
        errorMessages = new ArrayList<>();
        for (ObjectError error : errors.getAllErrors()) {
            errorMessages.add(messageSourceAccessor.getMessage(error));
        }
    }

    redirectAttributes.addFlashAttribute("deletedTags", tags);
    redirectAttributes.addFlashAttribute("errorMessages", errorMessages);
    return "redirect:/_admin/{language}/tags/index";
}

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

@RequestMapping
public String delete(@Valid @ModelAttribute("form") ArticleBulkDeleteForm form, BindingResult errors,
        String query, AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) {
    redirectAttributes.addAttribute("query", query);

    if (!form.isConfirmed()) {
        errors.rejectValue("confirmed", "Confirmed");
    }/*from w ww .j  a  va2 s  .  c o m*/
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "redirect:/_admin/{language}/articles/index";
    }

    Collection<Article> articles = null;
    try {
        articles = articleService.bulkDeleteArticle(form.buildArticleBulkDeleteRequest(), errors);
    } catch (ValidationException e) {
        if (errors.hasErrors()) {
            logger.debug("Errors: {}", errors);
            return "redirect:/_admin/{language}/articles/index";
        }
        throw e;
    }

    List<String> errorMessages = null;
    if (errors.hasErrors()) {
        errorMessages = new ArrayList<>();
        for (ObjectError error : errors.getAllErrors()) {
            errorMessages.add(messageSourceAccessor.getMessage(error));
        }
    }

    redirectAttributes.addFlashAttribute("deletedArticles", articles);
    redirectAttributes.addFlashAttribute("errorMessages", errorMessages);
    return "redirect:/_admin/{language}/articles/index";
}

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

@RequestMapping
public String delete(@Valid @ModelAttribute("form") UserBulkDeleteForm form, BindingResult errors, String query,
        AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) {
    redirectAttributes.addAttribute("query", query);

    if (!form.isConfirmed()) {
        errors.rejectValue("confirmed", "Confirmed");
    }//from w  w w  .java2 s  . c  om
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "redirect:/_admin/user/";
    }

    Collection<User> users = null;
    try {
        users = userService.bulkDeleteUser(form.buildUserBulkDeleteRequest(), errors);
    } catch (ValidationException e) {
        if (errors.hasErrors()) {
            logger.debug("Errors: {}", errors);
            return "redirect:/_admin/user/";
        }
        throw e;
    }

    List<String> errorMessages = null;
    if (errors.hasErrors()) {
        errorMessages = new ArrayList<>();
        for (ObjectError error : errors.getAllErrors()) {
            errorMessages.add(messageSourceAccessor.getMessage(error));
        }
    }

    redirectAttributes.addFlashAttribute("deletedArticles", users);
    redirectAttributes.addFlashAttribute("errorMessages", errorMessages);
    return "redirect:/_admin/{language}/users/index";
}

From source file:org.wallride.web.controller.admin.customfield.CustomFieldBulkDeleteController.java

@RequestMapping
public String delete(@Valid @ModelAttribute("form") CustomFieldBulkDeleteForm form, BindingResult errors,
        String query, AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) {
    redirectAttributes.addAttribute("query", query);

    if (!form.isConfirmed()) {
        errors.rejectValue("confirmed", "Confirmed");
    }/*  ww  w  .  ja  v  a  2s .co  m*/
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "redirect:/_admin/{language}/customfields/index";
    }

    Collection<CustomField> customFields = null;
    try {
        customFields = customFieldService.bulkDeleteCustomField(form.buildCustomFieldBulkDeleteRequest(),
                errors);
    } catch (ValidationException e) {
        if (errors.hasErrors()) {
            logger.debug("Errors: {}", errors);
            return "redirect:/_admin/{language}/customfields/index";
        }
        throw e;
    }

    List<String> errorMessages = null;
    if (errors.hasErrors()) {
        errorMessages = new ArrayList<>();
        for (ObjectError error : errors.getAllErrors()) {
            errorMessages.add(messageSourceAccessor.getMessage(error));
        }
    }

    redirectAttributes.addFlashAttribute("deletedCustomFields", customFields);
    redirectAttributes.addFlashAttribute("errorMessages", errorMessages);
    return "redirect:/_admin/{language}/customfields/index";
}

From source file:cn.edu.zjnu.acm.judge.contest.ContestController.java

@GetMapping("")
public String index(@PathVariable("contestId") long contestId, RedirectAttributes redirectAttributes) {
    redirectAttributes.addAttribute("contestId", contestId);
    return "redirect:/contests/{contestId}/problems";
}

From source file:cn.edu.zjnu.acm.judge.problem.ProblemStatusController.java

@GetMapping("/gotoproblem")
public String gotoProblem(@RequestParam(value = "pid", required = false) String pid,
        RedirectAttributes redirectAttributes) {
    try {/*  w w  w  . java2  s .co  m*/
        redirectAttributes.addAttribute("problem_id", Long.parseLong(pid));
        return "redirect:/showproblem";
    } catch (NumberFormatException ex) {
        redirectAttributes.addAttribute("sstr", pid);
        return "redirect:/searchproblem";
    }
}

From source file:ru.mystamps.web.controller.AccountController.java

@GetMapping(Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY)
public View showActivationFormWithKey(@PathVariable("key") String activationKey,
        RedirectAttributes redirectAttributes) {

    redirectAttributes.addAttribute("key", activationKey);

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.ACTIVATE_ACCOUNT_PAGE);

    return view;//from  ww  w . j  av  a 2s  .c  om
}

From source file:org.jessezhu.starriver.controller.TaskController.java

@RequestMapping(value = "delete/{id}")
public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAttributes) throws Exception {
    taskService.delete(id);/*from w ww  .j  a  v  a2s.c o m*/
    redirectAttributes.addAttribute("message", "?");
    return "redirect:/task/";
}

From source file:co.propack.sample.vendor.nullPaymentGateway.web.controller.NullPaymentGatewayHostedController.java

@Override
@RequestMapping(value = "/hosted/error", method = RequestMethod.GET)
public String errorEndpoint(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes,
        Map<String, String> pathVars) throws PaymentException {
    redirectAttributes.addAttribute(PAYMENT_PROCESSING_ERROR, request.getParameter(PAYMENT_PROCESSING_ERROR));
    return getOrderReviewRedirect();
}

From source file:co.propack.sample.vendor.nullPaymentGateway.web.controller.NullPaymentGatewayController.java

@Override
@RequestMapping(value = "/error", method = RequestMethod.GET)
public String errorEndpoint(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes,
        Map<String, String> pathVars) throws PaymentException {
    redirectAttributes.addAttribute(PAYMENT_PROCESSING_ERROR, request.getParameter(PAYMENT_PROCESSING_ERROR));
    return getOrderReviewRedirect();
}