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:de.whs.poodle.controllers.instructor.WorksheetsController.java

@RequestMapping(method = RequestMethod.POST, params = "unlockWorksheetId")
@PreAuthorize("@instructorSecurity.hasAccessToCourse(authentication.name, #courseId)")
public String unlock(@PathVariable int courseId, RedirectAttributes redirectAttributes,
        @RequestParam int unlockWorksheetId) {
    Worksheet worksheet = worksheetRepo.getById(unlockWorksheetId);

    try {/*from  www.  jav a2 s.  com*/
        worksheetUnlockEmailService.unlockWorksheetAndSendEmail(worksheet.getId());
        redirectAttributes.addFlashAttribute("okMessageCode",
                "worksheetUnlocked." + worksheet.getType().name());
    } catch (MailException | MessagingException e) {
        log.error("failed to send email", e);
        redirectAttributes.addFlashAttribute("errorMessageCode",
                "unlockEmailFailed." + worksheet.getType().name());
        redirectAttributes.addFlashAttribute("messageCodeParams", new Object[] { e.getMessage() });
    }

    return "redirect:/instructor/courses/{courseId}/worksheets";
}

From source file:com.redhat.rhtracking.web.controller.ConsultantController.java

@RequestMapping(value = "/consultant/add", method = RequestMethod.POST)
public String save(@Valid @ModelAttribute("consultantInfo") ConsultantInfo consultantInfo, BindingResult result,
        RedirectAttributes redirectAttributes, Model model, Principal principal) {
    List<String> messages = Utils.getMessagesList(model);
    redirectAttributes.addFlashAttribute("messages", messages);

    if (result.hasErrors()) {
        messages.add("warning::Datos incorrectos");
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.register", result);
        redirectAttributes.addFlashAttribute("consultantInfo", consultantInfo);
        return "redirect:/consultant/add";
    }/*from ww  w  .ja v a  2s . c  o  m*/

    Map<String, Object> request = new HashMap<>();
    request.put("name", consultantInfo.getName());
    request.put("partnerId", consultantInfo.getPartner());

    List<String> assignableHours = new ArrayList<>();
    if (consultantInfo.isPlatform())
        assignableHours.add("PLATFORM");
    if (consultantInfo.isMiddleware())
        assignableHours.add("MIDDLEWARE");
    if (consultantInfo.isWorkshop())
        assignableHours.add("WORKSHOP");
    request.put("assignableHours", assignableHours);

    Map<String, Object> response = consultantService.saveConsultant(request);
    if (response.get("status") == EventStatus.SUCCESS)
        messages.add("success::Consultor registrado");
    else {
        messages.add("error::Ocurrio un error al registrar el consultor.");
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.register", result);
        redirectAttributes.addFlashAttribute("consultantInfo", consultantInfo);
        return "redirect:/consultant/add";
    }

    return "redirect:/consultant/";
}

From source file:cz.muni.fi.mvc.controllers.DestinationController.java

/**
 * Shows a Destination/*from   ww  w.j  a  v a2 s  .c om*/
 * @param id identificator of the destination
 * @param model display data
 * @return jsp page
 */
@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
public String detail(@PathVariable long id, Model model, RedirectAttributes redirectAttributes,
        UriComponentsBuilder uriBuilder) {
    try {
        model.addAttribute("destination", destinationFacade.getDestinationWithId(id));
    } catch (Exception e) {
        redirectAttributes.addFlashAttribute("alert_danger", "Destination with id: " + id + " was not found.");
        return "redirect:" + uriBuilder.path("/destination").toUriString();
    }
    return "destination/detail";
}

From source file:cz.muni.pa165.carparkapp.web.AdminController.java

@RequestMapping(value = "branch/delete/{id}", method = RequestMethod.POST)
public String delete(@PathVariable int id, RedirectAttributes redirectAttributes, Locale locale,
        UriComponentsBuilder uriBuilder) {
    log.debug("delete({})", id);
    BranchDTO branch = branchService.findBranch(id);
    branchService.deleteBranch(branch);//from   ww  w . j  a v a  2s . c  om
    redirectAttributes.addFlashAttribute("message", messageSource.getMessage("addBranch.delete.mess",
            new Object[] { branch.getCompanyNumber() }, locale));
    return "redirect:" + uriBuilder.path("/admin/branch/addBranch").build();
}

From source file:me.doshou.admin.maintain.dynamictask.web.controller.DynamicTaskController.java

@Override
public String update(Model model, @Valid @ModelAttribute("m") TaskDefinition m, BindingResult result,
        @RequestParam(value = Constants.BACK_URL, required = false) String backURL,
        RedirectAttributes redirectAttributes) {
    if (permissionList != null) {
        this.permissionList.assertHasUpdatePermission();
    }/* ww w  .jav a  2s . c om*/

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

From source file:de.whs.poodle.controllers.AdminController.java

@RequestMapping(method = RequestMethod.POST, params = "email")
@PreAuthorize("@instructorSecurity.hasAdminAccess(authentication.name)")
@ConditionalOnProperty("poodle.emailEnabled")
public String email(@ModelAttribute Instructor instructor, @RequestParam String subject,
        @RequestParam String text, @RequestParam(required = false) boolean reply,
        RedirectAttributes redirectAttributes, Model model) {

    List<String> bccUsernames = userRepo.getAllEmailRecipients();

    try {// w w  w. j a v a  2s.  c  o  m
        emailService.sendMail(instructor, null, bccUsernames, reply, subject, text, true);
        redirectAttributes.addFlashAttribute("okMessageCode", "emailSent");
        return "redirect:/adminmenu";
    } catch (MailException | MessagingException | NullPointerException e) {
        model.addAttribute("errorMessageCode", "unknownMailError");
        model.addAttribute("messageCodeParams", new Object[] { e.getMessage() });
        return "adminmenu";
    }
}

From source file:org.schedoscope.metascope.controller.MetascopeDocumentationController.java

@RequestMapping(value = "/table/documentation/comment/delete", method = RequestMethod.POST)
public String deleteComment(HttpServletRequest request, RedirectAttributes redirAttr, String commentID) {
    MetascopeComment comment = documentationService.findById(commentID);
    MetascopeTable table = metascopeTableService.findByComment(comment);
    documentationService.deleteComment(table, comment, metascopeUserService.getUser());
    redirAttr.addFlashAttribute("comment", "deleted");
    return "redirect:" + request.getHeader("Referer");
}

From source file:com.zergiu.tvman.controllers.SettingsController.java

@RequestMapping(value = "/configuration", method = RequestMethod.POST)
public String configurationSave(@RequestParam(value = "location", required = false) String location,
        @RequestParam(value = "showProvider", required = false) String showProvider,
        RedirectAttributes redirectAttrs) {
    if (location != null) {
        configurationService.updateConfiguration(ConfigurationService.DEFAULT_LOCATION, location);
    }/* w  w w . jav a2s  .co m*/
    if (showProvider != null) {
        configurationService.updateConfiguration(ConfigurationService.DEFAULT_TVSHOWPROVIDER, showProvider);
    }

    redirectAttrs.addFlashAttribute("saveMessage", "tvman.configuration.saveOKMessage");
    redirectAttrs.addFlashAttribute("saveType", "alert-success");
    return "redirect:/settings/configuration";
}

From source file:com.dcampus.common.web.BaseController.java

/**
 * Flash?/*ww  w  .j a  v  a  2  s . com*/
 * @param message
 */
protected void addMessage(RedirectAttributes redirectAttributes, String... messages) {
    List<String> messageList = new ArrayList<String>();
    for (int i = 0; i < messages.length; i++) {
        messageList.add(messages[i]);
    }
    //   redirectAttributes.addAttribute("message", sb.toString());
    redirectAttributes.addFlashAttribute("message", messageList);
}

From source file:com.pw.ism.controllers.AccountController.java

@RequestMapping(value = "/pass", params = "form", method = RequestMethod.POST)
public ModelAndView changePass(User user, BindingResult bindingResult, Principal principal,
        RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        return new ModelAndView("account", "formErrors", bindingResult.getAllErrors());
    }//from www. j  a  v a2s  . c  o  m
    User currentUser = userRepo.findBySsoId(principal.getName());
    currentUser.setPassword(passEncoder.encode(user.getPassword()));
    userRepo.save(currentUser);
    redirectAttributes.addFlashAttribute("globalMessage", "Password changed");
    return new ModelAndView("redirect:/account");
}