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:com.trenako.web.controllers.RollingStocksController.java

@RequestMapping(method = RequestMethod.POST)
public String create(@ModelAttribute @Valid RollingStockForm form, BindingResult bindingResult, ModelMap model,
        RedirectAttributes redirectAtts) {

    MultipartFile file = form.getFile();
    RollingStock rs = form.buildRollingStock(valuesService, secContext, new Date());

    if (bindingResult.hasErrors()) {
        model.addAttribute(rejectForm(form, valuesService));
        return "rollingstock/new";
    }//from w ww  .j  a  v a 2s .c o  m

    try {
        service.createNew(rs);
        if (!file.isEmpty()) {
            imgService.saveImageWithThumb(UploadRequest.create(rs, file), 100);
        }

        redirectAtts.addFlashAttribute("message", ROLLING_STOCK_CREATED_MSG);
        redirectAtts.addAttribute("slug", rs.getSlug());
        return "redirect:/rollingstocks/{slug}";
    } catch (DuplicateKeyException duplEx) {
        log.error(duplEx.toString());
        model.addAttribute(newForm(rs, valuesService));
        model.addAttribute("message", ROLLING_STOCK_DUPLICATED_VALUE_MSG);
        return "rollingstock/new";
    } catch (DataAccessException dataEx) {
        log.error(dataEx.toString());
        model.addAttribute(newForm(rs, valuesService));
        model.addAttribute("message", ROLLING_STOCK_DATABASE_ERROR_MSG);
        return "rollingstock/new";
    }
}

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

@RequestMapping
public String delete(@Valid @ModelAttribute("form") ArticleDeleteForm form, BindingResult errors, String query,
        RedirectAttributes redirectAttributes) {
    //      if (!form.isConfirmed()) {
    //         errors.rejectValue("confirmed", "Confirmed");
    //      }//from   w w w .  j a v  a2  s.  co  m
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "article/describe";
    }

    Article article = null;
    try {
        article = articleService.deleteArticle(form.buildArticleDeleteRequest(), errors);
    } catch (BindException e) {
        if (errors.hasErrors()) {
            logger.debug("Errors: {}", errors);
            return "article/describe";
        }
        throw new RuntimeException(e);
    }

    redirectAttributes.addFlashAttribute("deletedArticle", article);
    redirectAttributes.addAttribute("query", query);
    return "redirect:/_admin/{language}/articles/index";
}

From source file:controllers.StrategyController.java

@RequestMapping("/addBodyModule")
public String addBodyModule(Map<String, Object> model, HttpServletRequest request,
        @RequestParam(value = "moduleId") Long moduleId, @RequestParam(value = "strategyId") Long strategyId,
        @RequestParam(value = "bodyText") String bodyText, RedirectAttributes ras) throws Exception {
    lk.dataByUserAndCompany(request, model);
    Long cabinetId = (Long) request.getSession().getAttribute(CABINET_ID_SESSION_NAME);
    if (moduleId != null) {
        moduleId = moduleService.addBodyText(moduleId, bodyText, cabinetId);
    } else {/*from w  w  w . ja  v  a2 s  .c o m*/
        ras.addFlashAttribute("errors", " ");
    }

    ras.addFlashAttribute("module", moduleService.showModule(moduleId));
    ras.addAttribute("strategyId", strategyId);
    ras.addAttribute("moduleId", moduleId);
    ras.addFlashAttribute("errors", moduleService.getErrors());
    return "redirect:/Strategy/strategy";
}

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

@RequestMapping(method = RequestMethod.POST)
public String update(@PathVariable String language, @Validated @ModelAttribute("form") CustomFieldEditForm form,
        BindingResult errors, String query, AuthorizedUser authorizedUser,
        RedirectAttributes redirectAttributes) {
    if (errors.hasErrors()) {
        return "customField/edit";
    }/*from   w  w w .  j  a v  a  2  s. co  m*/

    CustomField customField = null;
    try {
        customField = customFieldService.updateCustomField(form.buildCustomFieldUpdateRequest(),
                authorizedUser);
    } catch (EmptyCodeException e) {
        errors.rejectValue("code", "NotNull");
    } catch (DuplicateCodeException e) {
        errors.rejectValue("code", "NotDuplicate");
    }
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "customfield/edit";
    }

    redirectAttributes.addFlashAttribute("savedCustomField", customField);
    redirectAttributes.addAttribute("language", language);
    redirectAttributes.addAttribute("id", customField.getId());
    return "redirect:/_admin/{language}/customfields/index";
}

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

@RequestMapping(method = RequestMethod.POST, params = "publish")
public String saveAsPublished(@PathVariable String language,
        @Validated({ Default.class,
                PageCreateForm.GroupPublish.class }) @ModelAttribute("form") PageCreateForm form,
        BindingResult errors, String query, AuthorizedUser authorizedUser,
        RedirectAttributes redirectAttributes) {
    if (errors.hasErrors()) {
        return "page/create";
    }//from  w  ww  .j a  v  a 2 s  .  c  om

    Page page = null;
    try {
        page = pageService.createPage(form.buildPageCreateRequest(), Post.Status.PUBLISHED, authorizedUser);
    } catch (EmptyCodeException e) {
        errors.rejectValue("code", "NotNull");
    } catch (DuplicateCodeException e) {
        errors.rejectValue("code", "NotDuplicate");
    }
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "page/create";
    }

    redirectAttributes.addFlashAttribute("savedPage", page);
    redirectAttributes.addAttribute("language", language);
    redirectAttributes.addAttribute("id", page.getId());
    redirectAttributes.addAttribute("query", query);
    return "redirect:/_admin/{language}/pages/describe";
}

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

@RequestMapping(method = RequestMethod.POST)
public String save(@PathVariable String language, @Validated @ModelAttribute("form") CustomFieldCreateForm form,
        BindingResult errors, String query, AuthorizedUser authorizedUser,
        RedirectAttributes redirectAttributes) throws BindException {
    if (errors.hasErrors()) {
        return "customfield/create";
    }//w  w w.  j a v a  2  s .c  o m

    CustomField customfield = null;
    try {
        customfield = customfieldService.createCustomField(form.buildCustomFieldCreateRequest(),
                authorizedUser);
    } catch (EmptyCodeException e) {
        errors.rejectValue("code", "NotNull");
    } catch (DuplicateCodeException e) {
        errors.rejectValue("code", "NotDuplicate");
    }
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        return "customfield/create";
    }
    redirectAttributes.addFlashAttribute("savedCustomField", customfield);
    redirectAttributes.addAttribute("language", language);
    redirectAttributes.addAttribute("id", customfield.getId());
    return "redirect:/_admin/{language}/customfields/index";
}

From source file:controllers.StrategyController.java

@RequestMapping("/createFailReason")
public String createFailReason(Map<String, Object> model, HttpServletRequest request,
        @RequestParam(value = "failReasonName") String failReasonName,
        @RequestParam(value = "strategyId") Long strategyId, RedirectAttributes ras) throws Exception {

    lk.dataByUserAndCompany(request, model);
    Long cabinetId = (Long) request.getSession().getAttribute(CABINET_ID_SESSION_NAME);

    failReasonService.saveFailReason(failReasonName, strategyId, cabinetId);

    /*if (failReasonService.getErrors().isEmpty()) {
    ras.addFlashAttribute("message", "  " + failReasonName + " ?");
    }*//*from  ww w . ja v  a 2  s  .  c om*/
    ras.addFlashAttribute("errors", failReasonService.getErrors());
    ras.addAttribute("strategyId", strategyId);
    return "redirect:/Strategy/failReasonEditor";
}

From source file:rzd.vivc.documentexamination.controller.DocumentController.java

private String processEditRealisation(Part file, long documentID, DocumentForm document, Errors errors,
        RedirectAttributes model) {
    if (errors.hasErrors()) {
        addTypes(model);/*from  ww w .  j av  a  2 s . co m*/
        return "editDocument";
    }
    document.setFile(file);

    // ,   
    try {
        fileSavingService.saveUploadedFile(document);
    } catch (IOException e) {
        //?  ? ? 
        throw new FileLoadingException();
    }
    Document dtoDocument = document.toDocument();
    dtoDocument.setId(documentID);
    Document saved = documentAdditionalSavingServicesRepository.saveWythExaminations(dtoDocument);
    model.addAttribute("documentID", saved.getId());
    //    document. ?  ???   
    model.addFlashAttribute(saved);
    return "redirect:/director/document/{documentID}";
}

From source file:com.trenako.web.controllers.WishListsController.java

/**
 * Creates a new {@code WishList}.//from  w w  w . ja  v  a 2 s  .c o  m
 * <p/>
 * <p>
 * <pre><blockquote>
 * {@code POST /wishlists}
 * </blockquote></pre>
 * </p>
 */
@RequestMapping(method = RequestMethod.POST)
public String createWishList(@ModelAttribute @Valid WishListForm form, BindingResult bindingResult,
        ModelMap model, RedirectAttributes redirectAtts) {

    if (bindingResult.hasErrors()) {
        LogUtils.logValidationErrors(log, bindingResult);
        model.addAttribute("newForm", WishListForm.rejectForm(form, messageSource));
        return "wishlist/new";
    }

    try {
        Account owner = UserContext.authenticatedUser(userContext);
        WishList wishList = form.buildWishList(owner);
        service.createNew(wishList);

        WISH_LIST_CREATED_MSG.appendToRedirect(redirectAtts);

        redirectAtts.addAttribute("slug", wishList.getSlug());
        return "redirect:/you/wishlists/{slug}";
    } catch (DuplicateKeyException dke) {
        LogUtils.logException(log, dke);
        WISH_LIST_DUPLICATED_KEY_MSG.appendToModel(model);
    } catch (DataAccessException dae) {
        LogUtils.logException(log, dae);
        WISH_LIST_DB_ERROR_MSG.appendToModel(model);
    }

    model.addAttribute("newForm", WishListForm.rejectForm(form, messageSource));
    return "wishlist/new";
}

From source file:com.trenako.web.controllers.WishListsController.java

/**
 * <p>/*w  ww.  j  a va2  s .c  om*/
 * <pre><blockquote>
 * {@code PUT /wishlists}
 * </blockquote></pre>
 * </p>
 *
 * @param form          the {@code WishListForm} form
 * @param bindingResult the validation results
 * @param model         the model
 * @param redirectAtts  the redirect information
 * @return the view name
 */
@RequestMapping(method = RequestMethod.PUT)
public String saveWishList(@ModelAttribute @Valid WishListForm form, BindingResult bindingResult,
        ModelMap model, RedirectAttributes redirectAtts) {

    if (bindingResult.hasErrors()) {
        LogUtils.logValidationErrors(log, bindingResult);
        model.addAttribute("editForm", WishListForm.rejectForm(form, messageSource));
        return "wishlist/edit";
    }

    try {
        Account owner = UserContext.authenticatedUser(userContext);
        WishList wishList = form.buildWishList(owner);
        service.saveChanges(wishList);

        WISH_LIST_SAVED_MSG.appendToRedirect(redirectAtts);
        redirectAtts.addAttribute("slug", wishList.getSlug());
        return "redirect:/you/wishlists/{slug}";
    } catch (DuplicateKeyException dke) {
        LogUtils.logException(log, dke);
        WISH_LIST_DUPLICATED_KEY_MSG.appendToModel(model);
    } catch (DataAccessException dae) {
        LogUtils.logException(log, dae);
        WISH_LIST_DB_ERROR_MSG.appendToModel(model);
    }

    model.addAttribute("editForm", WishListForm.rejectForm(form, messageSource));
    return "wishlist/edit";
}