List of usage examples for org.springframework.web.servlet.mvc.support RedirectAttributes addFlashAttribute
RedirectAttributes addFlashAttribute(String attributeName, @Nullable Object attributeValue);
From source file:com.cme.hr.controller.PersonController.java
@RequestMapping(value = "/edit", method = RequestMethod.POST) public ModelAndView editPerson(@ModelAttribute Person person, BindingResult result, final RedirectAttributes redirectAttributes) throws PersonNotFound { ModelAndView mav = new ModelAndView("redirect:/person/list.html"); String message = "Person was successfully updated."; personService.update(person);/*w w w. j a v a2 s .c o m*/ redirectAttributes.addFlashAttribute("message", message); return mav; }
From source file:com.mtech.easyexchange.mvc.exchange.CreateOrderController.java
@RequestMapping(value = "/exchange/create-order/{currencyOne}/{currencyTwo}", method = RequestMethod.POST) public String process(@ActiveUser User user, @ModelAttribute("order") Order order, @RequestParam("action") String action, @PathVariable Currency currencyOne, @PathVariable Currency currencyTwo, RedirectAttributes redirectAttributes) { if (action.equals("buy")) { order.setBuyCurrency(Currency.BTC); order.setSellCurrency(Currency.LTC); } else {/*w w w. ja va 2s . c o m*/ order.setBuyCurrency(Currency.LTC); order.setSellCurrency(Currency.BTC); } order.setPlacedBy(user); try { orderManager.createOrder(order); redirectAttributes.addFlashAttribute("success", "You succesfully placed an order."); } catch (InsufficientFundsException e) { redirectAttributes.addFlashAttribute("error", "You do not have sufficient funds to place this order."); } return "redirect:/exchange/" + currencyOne.toString().toLowerCase() + "/" + currencyTwo.toString().toLowerCase(); }
From source file:mx.edu.um.mateo.general.web.UsuarioController.java
@Transactional @RequestMapping(value = "/elimina", method = RequestMethod.POST) public String elimina(@RequestParam Long id, Model modelo, @ModelAttribute Usuario usuario, BindingResult bindingResult, RedirectAttributes redirectAttributes) { log.debug("Elimina usuario"); try {//from ww w . j a v a 2 s . com String nombre = usuarioDao.elimina(id); redirectAttributes.addFlashAttribute("message", "usuario.eliminado.message"); redirectAttributes.addFlashAttribute("messageAttrs", new String[] { nombre }); } catch (UltimoException e) { log.error("No se pudo eliminar el usuario " + id, e); bindingResult.addError( new ObjectError("usuario", new String[] { "ultimo.usuario.no.eliminado.message" }, null, null)); List<Rol> roles = usuarioDao.roles(); modelo.addAttribute("roles", roles); return "admin/usuario/ver"; } catch (Exception e) { log.error("No se pudo eliminar el usuario " + id, e); bindingResult.addError( new ObjectError("usuario", new String[] { "usuario.no.eliminado.message" }, null, null)); List<Rol> roles = usuarioDao.roles(); modelo.addAttribute("roles", roles); return "admin/usuario/ver"; } return "redirect:/admin/usuario"; }
From source file:com.klm.workshop.controller.host.manage.UserController.java
/** * Delete user, based on the given user id. Then redirects to the index, * with a alert message.//from w ww . j ava2s. c o m * * @param id The ID of the user to delete * @param redirect The redirect attributes * @param locale The current client locale * @return Redirect to the index */ @RequestMapping(value = "/users/delete/{id}", method = RequestMethod.POST) public String getDelete(@PathVariable int id, RedirectAttributes redirect, Locale locale) { User user = (User) userDAO.findById(id); String success = messageSource.getMessage("general.delete_success", new String[] { user.getFullName() }, locale); userDAO.delete(user); redirect.addFlashAttribute("alertSuccess", success); return "redirect:/host/manage/users/index"; }
From source file:cz.swi2.mendeluis.app.web.controllers.PortletsController.java
/** * Set the user portlet visibility. /*from w ww .ja va 2s .c om*/ */ @PreAuthorize("hasPermission(#id, 'UserPortlet', 'isOwner')") @RequestMapping(value = "setVisibility/{id}", params = { "hidden" }, method = RequestMethod.GET) public String setVisibility(@PathVariable int id, @RequestParam(value = "hidden") int hidden, RedirectAttributes redirectAttributes, Principal principal) { UserPortletDTO up = userPortletFacade.getUserPortletWithId(id); userPortletFacade.setVisibility(up, (hidden == 1)); if (hidden == 1) { redirectAttributes.addFlashAttribute("alert_success", "Portlet is hidden."); } else { redirectAttributes.addFlashAttribute("alert_success", "Portlet is now visible."); } return "redirect:/portlets/"; }
From source file:com.logsniffer.web.controller.sniffer.SnifferStatusController.java
@RequestMapping(value = "/sniffers/{snifferId}/stopForm", method = RequestMethod.POST) String stop(@PathVariable("snifferId") final long snifferId, final Model model, final RedirectAttributes redirectAttrs) throws ResourceNotFoundException, SchedulerException { logger.info("Stopping sniffer: {}", snifferId); final Sniffer activeSniffer = getAndBindActiveSniffer(model, snifferId); snifferScheduler.stopSniffing(activeSniffer.getId()); logger.info("Stopped sniffer: {}", snifferId); redirectAttrs.addFlashAttribute("stopped", true); return "redirect:status"; }
From source file:es.ucm.fdi.dalgs.learningGoal.web.LearningGoalController.java
@RequestMapping(value = "/degree/{degreeId}/competence/{competenceId}/learninggoal/add.htm", method = RequestMethod.POST, params = "Undelete") // Every Post have to return redirect public String undeleteLearningGoalPOST(@PathVariable("competenceId") Long id_competence, @PathVariable("degreeId") Long id_degree, @ModelAttribute("learningGoal") LearningGoal learningGoal, BindingResult resultBinding, RedirectAttributes attr, Locale locale) { if (!resultBinding.hasErrors()) { ResultClass<LearningGoal> result = serviceLearningGoal.unDeleteLearningGoal(learningGoal, locale); if (!result.hasErrors()) { attr.addFlashAttribute("learningGoal", result.getSingleElement()); return "redirect:/degree/" + id_degree + "/competence/" + id_competence + "/learninggoal/" + result.getSingleElement().getId() + "/modify.htm"; } else {// w ww . j a va 2 s . co m if (result.isElementDeleted()) attr.addFlashAttribute("unDelete", true); attr.addFlashAttribute("errors", result.getErrorsList()); } } else { attr.addFlashAttribute("org.springframework.validation.BindingResult.learningGoal", resultBinding); } attr.addFlashAttribute("learningGoal", learningGoal); return "reidrect:/degree/" + id_degree + "/competence/" + id_competence + "/learninggoal/add.htm"; }
From source file:de.siegmar.securetransfer.controller.SendController.java
/** * Handle burn request sent by the sender. *//* ww w. j av a 2 s. c o m*/ @DeleteMapping("/{id:[a-f0-9]{64}}") public String burn(@PathVariable("id") final String id, @RequestParam("linkSecret") final String linkSecret, final RedirectAttributes redirectAttributes) { final SenderMessage senderMessage = messageService.getSenderMessage(id); if (senderMessage.getReceived() != null) { redirectAttributes.addFlashAttribute("alreadyReceived", true); } else if (senderMessage.getBurned() != null) { redirectAttributes.addFlashAttribute("alreadyBurned", true); } else if (senderMessage.getInvalidated() != null) { redirectAttributes.addFlashAttribute("alreadyInvalidated", true); } else { messageService.burnSenderMessage(senderMessage); redirectAttributes.addFlashAttribute("messageBurned", true); } return String.format("redirect:/send/%s?linkSecret=%s", id, linkSecret); }
From source file:com.klm.workshop.controller.host.manage.WorkshopController.java
/** * Delete workshop, based on the given workshop id. Then redirects to the * index, with a alert message.//ww w. j a v a 2 s. com * * @param id The ID of the workshop to delete * @param redirect The redirect attributes * @param locale The current client locale * @return Redirect to the index */ @RequestMapping(value = "/workshops/delete/{id}", method = RequestMethod.POST) public String getDelete(@PathVariable int id, RedirectAttributes redirect, Locale locale) { Workshop workshop = (Workshop) workshopDAO.findById(id); String success = messageSource.getMessage("general.delete_success", new String[] { workshop.getName() }, locale); workshopDAO.delete(workshop); redirect.addFlashAttribute("alertSuccess", success); return "redirect:/host/manage/workshops/index"; }
From source file:controllers.admin.SignupController.java
@PostMapping("/signup") public String processSignup(@Validated(User.UserCreation.class) @ModelAttribute User user, Errors errors, RedirectAttributes model) { String viewName = "admin/signup"; if (!errors.hasErrors()) { try {/*w ww .j a v a2 s.c om*/ userService.create(user); List<String> successMessages = new ArrayList(); successMessages.add(messageSource.getMessage("message.signup.success", new Object[] { user.getUsername() }, Locale.getDefault())); model.addFlashAttribute("successFlashMessages", successMessages); viewName = "redirect:/admin/login"; } catch (UserAlredyExistsException e) { logger.error("Email alredy exists"); errors.rejectValue("email", "user.exists"); } } return viewName; }