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:cz.muni.fi.pa165.mvc.controllers.TeamController.java

@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
public String delete(@PathVariable long id, Model model, UriComponentsBuilder uriBuilder,
        RedirectAttributes redirectAttributes) {
    try {/*from   ww  w. j  a v a2 s .com*/
        TeamDTO team = teamFacade.getTeamById(id);
        teamFacade.deleteTeam(id);
        redirectAttributes.addFlashAttribute("alert_success", "Team: " + team.toString() + " was deleted.");
    } catch (Exception ex) {
        log.warn("cannot delete team {}", id);
        redirectAttributes.addFlashAttribute("alert_danger",
                "This team cannot be deleted because it is being matched with another team in La Liga now.");
    }
    return "redirect:" + uriBuilder.path("/team/list").toUriString();
}

From source file:de.whs.poodle.controllers.instructor.WorksheetEditorController.java

@RequestMapping(method = RequestMethod.POST, params = { "renameChapterId", "chapterTitle" })
@PreAuthorize("@instructorSecurity.hasAccessToWorksheet(authentication.name, #worksheetId)")
public String renameChapter(@PathVariable int worksheetId, @RequestParam int renameChapterId,
        @RequestParam String chapterTitle, RedirectAttributes redirectAttributes) {
    try {/*from   ww w.  j a v a2  s .  c  o m*/
        exerciseWorksheetRepo.renameChapter(renameChapterId, chapterTitle);
    } catch (BadRequestException e) {
        redirectAttributes.addFlashAttribute("errorMessageCode", "noTitleSpecified");
    }
    return "redirect:/instructor/worksheets/{worksheetId}/edit";
}

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

@RequestMapping(value = "/matrix/add", method = RequestMethod.POST)
public String save(@Valid @ModelAttribute("deliveryMatrixInfo") DeliveryMatrixInfo deliveryMatrixInfo,
        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("deliveryMatrixInfo", deliveryMatrixInfo);
        return "redirect:/matrix/add?id=" + deliveryMatrixInfo.getOpportunity();
    }/*www . java  2  s.  c om*/

    Map<String, Object> request = new HashMap<>();

    request.put("salesOrder", deliveryMatrixInfo.getSalesOrder());
    request.put("opportunityIdentifier", deliveryMatrixInfo.getOpportunity());
    request.put("startDate", deliveryMatrixInfo.getStartDate());
    request.put("endDate", deliveryMatrixInfo.getEndDate());
    request.put("payNow", deliveryMatrixInfo.isPayNow());
    request.put("deliveryStatus", deliveryMatrixInfo.getDeliveryStatus());
    request.put("deliverySubStatus", deliveryMatrixInfo.getDeliverySubStatus());
    request.put("deliveryProbability", deliveryMatrixInfo.getDeliveryProbability());

    Map<String, Object> response = deliveryMatrixService.saveDeliveryMatrix(request);
    if (response.get("status") == com.redhat.rhtracking.events.EventStatus.SUCCESS)
        messages.add("success::Agregado correctamente");
    else
        messages.add("error::Ocurrio un error al registrar la matriz de entrega.");
    return "redirect:/opportunity/show?id=" + deliveryMatrixInfo.getOpportunity();
}

From source file:controllers.CCOController.java

@RequestMapping("/updateAllInGroup")
public String updateAllInGroup(Map<String, Object> model, @RequestParam("oldGroupId") Long oldGroupId,
        @RequestParam("uid") String uid, @RequestParam("paramValue") String paramValue,
        @RequestParam("percentValue") Long percentValue,
        @RequestParam(value = "audial", required = false) Integer audial,
        @RequestParam(value = "visual", required = false) Integer visual,
        @RequestParam(value = "kinestet", required = false) Integer kinestet,
        @RequestParam("radical") String radical, RedirectAttributes ras) throws Exception {
    carCompletionGroupService.updateAllInGroup(oldGroupId, uid, paramValue, percentValue, radical, audial,
            visual, kinestet);/* ww w  .jav a  2 s  .  c om*/
    ras.addFlashAttribute("error", carCompletionGroupService.getResult().getErrors());
    return "redirect:/CCO/show";
}

From source file:com.springmvc.videoteca.springtiles.controller.ClienteController.java

@RequestMapping(value = "/registrar.htm", method = RequestMethod.POST)
public String saveOrUpdateCliente(@ModelAttribute("clienteForm") @Validated Cliente cliente,
        BindingResult result, Model model, final RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "Cliente/registrarse";
    } else {/*  www.j  av a  2  s  .  c  om*/

        if (cliente.esNuevo()) {
            redirectAttributes.addFlashAttribute("msg", "Cliente agregado correctamente!");
        } else {
            redirectAttributes.addFlashAttribute("msg", "Cliente modificado correctamente!");
        }

        clienteService.saveOrUpdate(cliente);
        return "redirect:/Cliente/" + cliente.getId();
    }
}

From source file:com.dams.controller.client.ClientController.java

@RequestMapping(value = "/client/signup", method = RequestMethod.POST)
public String processRegister(@ModelAttribute("patient") @Valid Patient patient, BindingResult result,
        RedirectAttributes redirectAttributes) {

    if (result.hasErrors()) {
        return "signup";
    }//from ww  w . j ava  2 s .  c o  m
    patientService.savePatient(patient);
    redirectAttributes.addFlashAttribute("message", "Registered Successfully");
    return "redirect:/client/doctors";
}

From source file:cz.muni.fi.pa165.mvc.controllers.LoginController.java

@RequestMapping(value = "/trylogin", method = RequestMethod.POST)
public String trylogin(HttpServletRequest request, @Valid @ModelAttribute("userDTO") UserCreateDTO formBean,
        BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes,
        UriComponentsBuilder uriBuilder) {
    UserDTO matchingUser = userFacade.findUserByEmail(formBean.getEmail());
    if (matchingUser == null) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Wrong parameters, email or password doesn`t match");
        return "redirect:" + uriBuilder.path("/user/login").toUriString();
    }/*from  ww  w . ja  v a  2 s  .c  o m*/
    UserAuthenticateDTO userAuthenticateDTO = new UserAuthenticateDTO();
    userAuthenticateDTO.setUserId(matchingUser.getId());
    userAuthenticateDTO.setPassword(formBean.getPassword());

    if (!userFacade.isAdmin(matchingUser)) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Wrong parameters, email or password doesn`t match");
        return "redirect:" + uriBuilder.path("/user/login").toUriString();
    }
    if (!userFacade.authenticate(userAuthenticateDTO)) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Wrong parameters, email or password doesn`t match");
        return "redirect:" + uriBuilder.path("/user/login").toUriString();
    }
    log.trace("user", matchingUser);
    request.getSession().setAttribute("authenticatedUser", matchingUser);
    return "redirect:" + uriBuilder.path("/").toUriString();

}

From source file:de.whs.poodle.controllers.student.SelfStudyController.java

@RequestMapping(method = RequestMethod.POST)
@PreAuthorize("@studentSecurity.hasAccessToCourseTerm(authentication.name, #courseTermId)")
public String postFeedback(@PathVariable int courseTermId, @ModelAttribute Student student,
        @ModelAttribute FeedbackForm form, RedirectAttributes redirectAttributes) {
    int studentId = student.getId();

    feedbackRepo.saveFeedbackAndRemoveExerciseFromSelfStudy(form, studentId, courseTermId);

    if (form.isEmpty())
        redirectAttributes.addFlashAttribute("okMessageCode", "exerciseRemovedFromWorksheet");
    else//from w  ww.  j  a  v a2 s  . c  om
        redirectAttributes.addFlashAttribute("okMessageCode", "exerciseRemovedFromWorksheetWithThanks");

    return "redirect:/student/selfStudy/{courseTermId}";
}

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

@PostMapping(Url.ADD_CATEGORY_PAGE)
public String processInput(@Valid AddCategoryForm form, BindingResult result,
        @CurrentUser Integer currentUserId, RedirectAttributes redirectAttributes) {

    if (result.hasErrors()) {
        return null;
    }//from w  w w .j a v a 2  s.  c  om

    String slug = categoryService.add(form, currentUserId);

    redirectAttributes.addFlashAttribute("justAddedCategory", true);

    return redirectTo(Url.INFO_CATEGORY_PAGE, slug);
}

From source file:controllers.TagController.java

@RequestMapping("/create")
public String createTag(Map<String, Object> model, HttpServletRequest request,
        @RequestParam(value = "name") String name, RedirectAttributes ras) throws Exception {
    lk.dataByUserAndCompany(request, model);
    Long cabinetId = (Long) request.getSession().getAttribute(CABINET_ID_SESSION_NAME);
    tagService.create(name, cabinetId);//from   w  w w. java  2 s. c om
    ras.addFlashAttribute("errors", tagService.getErrors());
    ras.addFlashAttribute("name", name);
    return "redirect:/Tag/show";
}