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

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

Introduction

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

Prototype

RedirectAttributes addFlashAttribute(String attributeName, @Nullable Object attributeValue);

Source Link

Document

Add the given flash attribute.

Usage

From source file:mvc.parent.WebController.java

protected void addErrorToRedirecrt(RedirectAttributes ra, String error) {
    List<String> errors = new ArrayList();
    errors.add(error);/*from   w w  w. j a v a  2s .c o m*/
    ra.addFlashAttribute(ERRORS_LIST_NAME, errors);
}

From source file:cn.guoyukun.spring.jpa.web.controller.BaseCRUDController.java

@RequestMapping(value = "{id}/update", method = RequestMethod.POST)
public String update(Model model, @Valid @ModelAttribute("m") M m, BindingResult result,
        @RequestParam(value = Constants.BACK_URL, required = false) String backURL,
        RedirectAttributes redirectAttributes) {

    if (permissionList != null) {
        this.permissionList.assertHasUpdatePermission();
    }/*from w w w. j ava 2 s .  c o m*/

    if (hasError(m, result)) {
        return showUpdateForm(m, model);
    }
    baseService.update(m);
    redirectAttributes.addFlashAttribute(Constants.MESSAGE, "?");
    return redirectToUrl(backURL);
}

From source file:com.mascova.caliga.controller.UserController.java

@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@Valid UserForm userForm, BindingResult result, Model model,
        RedirectAttributes redirectAttributes, HttpServletRequest request) {

    if (result.hasErrors()) {
        model.addAttribute("userForm", userForm);
        model.addAttribute("auths", authorityService.getAll());
        return "user/user-detail";
    }//from   w  ww.  j  a  v  a  2s .  c om
    User user = userForm.bindToModel(new User());
    userService.saveOrUpdate(user);

    redirectAttributes.addFlashAttribute("statusMessageKey", new StringBuilder("User created: ")
            .append(user.getFirstName()).append(" ").append(user.getLastName()).toString());
    return "redirect:index";
}

From source file:mx.edu.um.mateo.rh.web.JefeRHController.java

@Transactional
@RequestMapping(value = "/elimina", method = RequestMethod.POST)
public String elimina(HttpServletRequest request, @RequestParam Long id, Model modelo,
        @ModelAttribute Jefe jefe, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
    log.debug("Elimina clave de empleado");
    try {/*from   w w w. jav  a 2 s  .c  om*/
        manager.elimina(id);

        redirectAttributes.addFlashAttribute(Constantes.CONTAINSKEY_MESSAGE, "jefe.elimina.message");
        redirectAttributes.addFlashAttribute(Constantes.CONTAINSKEY_MESSAGE_ATTRS,
                new String[] { jefe.getJefe().getNombre() });
    } catch (Exception e) {
        log.error("No se pudo eliminar la clave con id" + id, e);
        bindingResult.addError(new ObjectError(Constantes.ADDATTRIBUTE_JEFE,
                new String[] { "jefe.no.elimina.message" }, null, null));
        return Constantes.PATH_JEFE_VER;
    }

    return "redirect:" + Constantes.PATH_JEFE_LISTA;
}

From source file:com.epam.training.storefront.controllers.pages.payment.SilentOrderPostMockController.java

@RequestMapping(value = "/handle-form-post", method = RequestMethod.POST)
public String handleFormPost(@Valid final SopPaymentDetailsForm form, final BindingResult bindingResult,
        @RequestParam("targetArea") final String targetArea, @RequestParam("editMode") final Boolean editMode,
        @RequestParam("paymentInfoId") final String paymentInfoId,
        final RedirectAttributes redirectAttributes) {
    getSopPaymentDetailsValidator().validate(form, bindingResult);
    if (bindingResult.hasErrors()) {
        redirectAttributes.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER,
                Collections.singletonList("checkout.error.paymentmethod.formentry.invalid"));
        redirectAttributes.addFlashAttribute(
                "org.springframework.validation.BindingResult.sopPaymentDetailsForm", bindingResult);
        redirectAttributes.addFlashAttribute("sopPaymentDetailsForm", bindingResult.getTarget());

        return Boolean.TRUE.equals(editMode) ? REDIRECT_URL_EDIT_PAYMENT_DETAILS + paymentInfoId
                : REDIRECT_URL_ADD_PAYMENT_METHOD + targetArea;

    } else {// w w w  . ja v a 2s .co  m
        final String authorizationRequestId = (String) getSessionService()
                .getAttribute("authorizationRequestId");
        final String authorizationRequestToken = (String) getSessionService()
                .getAttribute("authorizationRequestToken");

        try {
            if (BooleanUtils.isTrue(editMode)) {
                final CCPaymentInfoData ccPaymentInfoData = setupCCPaymentInfoData(form, paymentInfoId);
                if (null != ccPaymentInfoData) {
                    final CCPaymentInfoData result = getSubscriptionFacade()
                            .changePaymentMethod(ccPaymentInfoData, null, true, null);

                    // enrich result data with form data, which is not provided from the facade call
                    result.setId(paymentInfoId);
                    result.getBillingAddress()
                            .setTitleCode(ccPaymentInfoData.getBillingAddress().getTitleCode());
                    result.setStartMonth(ccPaymentInfoData.getStartMonth());
                    result.setStartYear(ccPaymentInfoData.getStartYear());
                    result.setIssueNumber(ccPaymentInfoData.getIssueNumber());

                    getUserFacade().updateCCPaymentInfo(result);

                    if (form.getMakeAsDefault().booleanValue()) {
                        getUserFacade().setDefaultPaymentInfo(result);
                    }

                    redirectAttributes.addFlashAttribute(GlobalMessages.CONF_MESSAGES_HOLDER,
                            Collections.singletonList("text.account.paymentDetails.editSuccessful"));
                } else {
                    redirectAttributes.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER,
                            Collections.singletonList("text.account.paymentDetails.nonExisting.error"));
                }
            } else {
                final SubscriptionPaymentData result = getSubscriptionFacade().finalizeTransaction(
                        authorizationRequestId, authorizationRequestToken,
                        createPaymentDetailsMap(form, targetArea));

                final CCPaymentInfoData newPaymentSubscription = getSubscriptionFacade()
                        .createPaymentSubscription(result.getParameters());

                // enrich result data with form data, which is not provided from the facade call
                newPaymentSubscription.setStartMonth(form.getStartMonth());
                newPaymentSubscription.setStartYear(form.getStartYear());
                newPaymentSubscription.setIssueNumber(form.getIssueNumber());
                newPaymentSubscription.setSaved(true);

                getUserFacade().updateCCPaymentInfo(newPaymentSubscription);

                if (form.getMakeAsDefault().booleanValue()) {
                    getUserFacade().setDefaultPaymentInfo(newPaymentSubscription);
                }

                getCheckoutFacade().setPaymentDetails(newPaymentSubscription.getId());

                redirectAttributes.addFlashAttribute(GlobalMessages.CONF_MESSAGES_HOLDER,
                        Collections.singletonList("text.account.paymentDetails.addSuccessful"));
            }
        } catch (final SubscriptionFacadeException e) {
            LOG.error("Creating a new payment method failed", e);
            redirectAttributes.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER,
                    Collections.singletonList("checkout.multi.paymentMethod.addPaymentDetails.incomplete"));
            return REDIRECT_URL_ADD_PAYMENT_METHOD + targetArea;
        }
    }

    if (StringUtils.equals(targetArea, "multiCheckoutArea")) {
        return REDIRECT_URL_SUMMARY;
    }

    return REDIRECT_URL_PAYMENT_INFO;
}

From source file:mx.edu.um.mateo.rh.web.VacacionesEmpleadoController.java

@Transactional
@RequestMapping(value = "/elimina", method = RequestMethod.POST)
public String elimina(HttpServletRequest request, @RequestParam Long id, Model modelo,
        @ModelAttribute VacacionesEmpleado vacacionesEmpleado, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    log.debug("Elimina clave de empleado");
    try {/* w w  w. ja va  2 s .com*/
        manager.elimina(id);

        redirectAttributes.addFlashAttribute(Constantes.CONTAINSKEY_MESSAGE,
                "vacacionesEmpleado.elimina.message");
        redirectAttributes.addFlashAttribute(Constantes.CONTAINSKEY_MESSAGE_ATTRS,
                new String[] { vacacionesEmpleado.getDescripcion() });
    } catch (Exception e) {
        log.error("No se pudo eliminar la clave con id" + id, e);
        bindingResult.addError(new ObjectError(Constantes.ADDATTRIBUTE_VACACIONESEMPLEADO,
                new String[] { "vacacionesEmpleado.no.elimina.message" }, null, null));
        return Constantes.PATH_VACACIONESEMPLEADO_VER;
    }

    return "redirect:" + Constantes.PATH_VACACIONESEMPLEADO_LISTA;
}

From source file:com.example.securelogin.app.account.AccountController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@Validated({ CreateAccount.class, Default.class }) AccountCreateForm form,
        BindingResult result, RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return createForm();
    }// w  ww  . java 2  s  . c om
    Account account = beanMapper.map(form, Account.class);
    List<Role> roles = Arrays.asList(Role.USER);
    account.setRoles(roles);
    String password = accountSharedService.create(account, form.getImageId());
    redirectAttributes.addFlashAttribute("firstName", form.getFirstName());
    redirectAttributes.addFlashAttribute("lastName", form.getLastName());
    redirectAttributes.addFlashAttribute("password", password);
    return "redirect:/accounts/create?complete";
}

From source file:com.cloudbees.demo.beesshop.web.ShoppingCartController.java

@RequestMapping(method = RequestMethod.POST, value = "/cart/buy")
public String buy(HttpServletRequest request, RedirectAttributes redirectAttributes) {
    ShoppingCart shoppingCart = shoppingCartRepository.getCurrentShoppingCart(request);

    salesRevenueInCentsCounter.addAndGet(shoppingCart.getPriceInCents());
    salesItemsCounter.addAndGet(shoppingCart.getItemsCount());
    salesOrdersCounter.incrementAndGet();

    shoppingCartRepository.resetCurrentShoppingCart(request);
    redirectAttributes.addFlashAttribute("successMessage", "Thanks for buying on the Bees Shop");
    return "redirect:/";
}

From source file:cz.swi2.mendeluis.app.web.controllers.FavouriteItemController.java

/**
 * Remove the attached favourite user favourite item from the current user. 
 *//*from  ww  w .j  a v  a2s .c o  m*/
@RequestMapping(value = "remove/{id}", method = RequestMethod.GET)
public String remove(@PathVariable int id, RedirectAttributes redirectAttributes, Principal principal) {

    UserDTO user = userFacade.getLoggedUser();
    UserDTO user2 = uFavFacade.getUserFavouriteItemWithId(id).getUser();

    if (!user.getUsername().equals(user2.getUsername())) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "You cannot remove a favourite item that is not yours!");
        return "redirect:/favourites/";
    }
    UserFavouriteItemDTO ufav = uFavFacade.getUserFavouriteItemWithId(id);
    FavouriteItemDTO fav = ufav.getFavouriteItem();
    uFavFacade.deleteUserFavouriteItem(id);
    if (fav != null && fav.getName().equals("u_item")) {
        int fid = fav.getId();
        favFacade.deleteFavouriteItem(fid);
    }

    redirectAttributes.addFlashAttribute("alert_success", "Favourite item was detached.");
    return "redirect:/favourites/";
}

From source file:mx.edu.um.mateo.rh.web.SolicitudVacacionesEmpleadoController.java

@Transactional
@RequestMapping(value = "/elimina", method = RequestMethod.POST)
public String elimina(HttpServletRequest request, @RequestParam Long id, Model modelo,
        @ModelAttribute SolicitudVacacionesEmpleado vacaciones, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    log.debug("Elimina clave de empleado");
    try {/*w ww .  j a  v a  2 s  .  c o m*/
        manager.elimina(id);

        redirectAttributes.addFlashAttribute(Constantes.CONTAINSKEY_MESSAGE, "vacaciones.elimina.message");
        redirectAttributes.addFlashAttribute(Constantes.CONTAINSKEY_MESSAGE_ATTRS,
                new String[] { vacaciones.getEmpleado().getNombre() });
    } catch (Exception e) {
        log.error("No se pudo eliminar la clave con id" + id, e);
        bindingResult.addError(new ObjectError(Constantes.ADDATTRIBUTE_SOLICITUDVACACIONESEMPLEADO,
                new String[] { "vacaciones.no.elimina.message" }, null, null));
        return Constantes.PATH_SOLICITUDVACACIONESEMPLEADO_VER;
    }

    return "redirect:" + Constantes.PATH_SOLICITUDVACACIONESEMPLEADO_LISTA;
}