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:mx.edu.um.mateo.rh.web.DiaFeriadoController.java

@Transactional
@RequestMapping(value = "/elimina", method = RequestMethod.POST)
public String elimina(HttpServletRequest request, @RequestParam Long id, Model modelo,
        @ModelAttribute DiaFeriado diaFeriado, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    log.debug("Elimina clave de empleado");
    try {/*  www  .  j a v  a2s.c  om*/
        manager.elimina(id);

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

    return "redirect:" + Constantes.PATH_DIAFERIADO_LISTA;
}

From source file:mx.edu.um.mateo.general.web.OrganizacionController.java

@RequestMapping(value = "/elimina", method = RequestMethod.POST)
public String elimina(HttpSession session, @RequestParam Long id, Model modelo,
        @ModelAttribute Organizacion organizacion, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    log.debug("Elimina organizacion");
    try {//from   w w w. j  a  va  2  s.  co  m
        String nombre = organizacionDao.elimina(id);

        ambiente.actualizaSesion(session);

        redirectAttributes.addFlashAttribute("message", "organizacion.eliminada.message");
        redirectAttributes.addFlashAttribute("messageAttrs", new String[] { nombre });
    } catch (UltimoException e) {
        log.error("No se pudo eliminar el organizacion " + id, e);
        bindingResult.addError(new ObjectError("organizacion",
                new String[] { "ultima.organizacion.no.eliminada.message" }, null, null));
        return "admin/organizacion/ver";
    } catch (Exception e) {
        log.error("No se pudo eliminar el organizacion " + id, e);
        bindingResult.addError(new ObjectError("organizacion",
                new String[] { "organizacion.no.eliminada.message" }, null, null));
        return "admin/organizacion/ver";
    }

    return "redirect:/admin/organizacion";
}

From source file:mx.edu.um.mateo.colportor.web.PedidoColportorController.java

@RequestMapping(value = "/elimina", method = RequestMethod.POST)
public String elimina(HttpServletRequest request, @RequestParam Long id, Model modelo,
        @ModelAttribute PedidoColportor pedidoColportor, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    log.debug("Elimina pedidoColportor");
    try {/*  w  ww  . ja v a 2s . c  o  m*/
        String nombre = pedidoColportorDao.elimina(id);

        redirectAttributes.addFlashAttribute("message", "pedidoColportor.eliminado.message");
        redirectAttributes.addFlashAttribute("messageAttrs", new String[] { nombre });
    } catch (Exception e) {
        log.error("No se pudo eliminar la pedidoColportor " + id, e);
        bindingResult.addError(new ObjectError("pedidoColportor",
                new String[] { "pedidoColportor.no.eliminado.message" }, null, null));
        return Constantes.PEDIDO_COLPORTOR_PATH_VER;
    }

    return "redirect:" + Constantes.PEDIDO_COLPORTOR_PATH;
}

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

@RequestMapping(value = "create", method = RequestMethod.POST)
public String create(Model model, @Valid @ModelAttribute("m") M m, BindingResult result,
        RedirectAttributes redirectAttributes) {

    if (permissionList != null) {
        this.permissionList.assertHasCreatePermission();
    }/*from w  ww . j a  v  a 2  s  .co  m*/

    if (hasError(m, result)) {
        return showCreateForm(model);
    }
    baseService.save(m);
    redirectAttributes.addFlashAttribute(Constants.MESSAGE, "?");
    return redirectToUrl(null);
}

From source file:eu.scidipes.toolkits.pawebapp.web.AdminController.java

@RequestMapping("/templates/deletebundle")
public String deleteTemplateBundle(final String bundleName, final RedirectAttributes redirectAttrs) {

    final Long datasetCount = datasetRepo.countDatasetsByBundle(bundleName);

    if (datasetCount.longValue() > 0) {
        LOG.info("Cannot delete bundle '{}' in use by {} datasets", bundleName, datasetCount.toString());
        redirectAttrs.addFlashAttribute("errorKey", DELETE_FAIL_IN_USE);
        return "redirect:/admin/templates/";
    }/*from   w  w  w .  j  a  v  a  2 s  .co m*/

    boolean success = false;

    try {
        final FormsBundle bundleToDelete = libraryAPI.getEmptyStructureForBundle(bundleName);

        /* Attempt to delete the template source file first: */
        final String processorName = bundleToDelete.getProcessorName();

        final PreservationDatasourceProcessor processor = SourceProcessorManager.INSTANCE.getProcessors()
                .get(processorName);

        final StringBuilder sourcePath = new StringBuilder();
        sourcePath.append(SOURCE_ROOT_PATH + File.separatorChar);
        sourcePath.append(processor.getClass().getSimpleName() + File.separatorChar);
        sourcePath.append(bundleToDelete.getTemplateSource());

        final File source = new File(sourcePath.toString());

        if (source.delete()) {
            LOG.info("Successfully deleted source file: {}", source);
            success = libraryAPI.deleteBundle(bundleToDelete);
        }

    } catch (final PreservationException e) {
        LOG.error(e.toString(), e);
    }

    if (success) {
        LOG.info("Successfully deleted bundle: {}", bundleName);
        redirectAttrs.addFlashAttribute("msgKey", DELETE_SUCCESS);
        return "redirect:/admin/templates/";
    } else {
        redirectAttrs.addFlashAttribute("errorKey", DELETE_FAIL);
        return "redirect:/admin/templates/";
    }

}

From source file:ask.springboot.controller.XiangLiaoController.java

@RequestMapping(value = "/delete")
public ModelAndView deleteall(RedirectAttributes ra) {
    ModelAndView result = new ModelAndView("redirect:/xiangliao");

    xiangliaoService.deleteAll();//from w  ww.j  av  a  2 s.c  o  m

    ra.addFlashAttribute("msg", "?!");
    return result;
}

From source file:org.zhangmz.pickles.controller.UserIndexController.java

/**
 * /*from   w w w .  j a  v a 2s  .co m*/
 * @Title: login 
 * @Description: 
 * @param groupCode   ?
 * @param phoneEmail  ??Email
 * @param password    ?
 * @param redirectAttributes
 * @return
 * @throws 
 * :
 * :2016125 ?7:14:05
 * ?????Email??
 * ??ID??
 */
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestParam(value = "groupCode", required = false) String groupCode,
        @RequestParam("phoneEmail") String phoneEmail, @RequestParam("password") String password,
        RedirectAttributes redirectAttributes) {
    String token;
    String url;

    try {
        logger.debug("groupCode:" + groupCode + ", phoneEmail:" + phoneEmail + ", password:" + password);
        // token = accountService.login(phoneEmail, password);
        token = accountService.login(groupCode, phoneEmail, password);
        redirectAttributes.addFlashAttribute("TOKEN", token);

        // ???
        if (accountService.isAdmin(token)) {
            // accountService.invalidateAccount(token);
            // ??
            url = AdminUrl.redirectMainController + "?TOKEN=" + token;
        } else {
            // redirectAttributes.addFlashAttribute("message", Messages.USER_NOT_ADMIN);
            url = UserUrl.redirectMainController + "?TOKEN=" + token;
        }

    } catch (Exception e) {
        // e.printStackTrace();
        redirectAttributes.addFlashAttribute("message", e.getMessage());
        url = UserUrl.redirectLoginController;
    }

    return url;
}

From source file:mx.edu.um.mateo.contabilidad.web.EjercicioController.java

@RequestMapping(value = "/elimina", method = RequestMethod.POST)
public String elimina(HttpServletRequest request, @RequestParam String id, Model modelo,
        @ModelAttribute Ejercicio ejercicio, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    log.debug("Elimina ejercicio");
    try {/*  w  ww .  j  ava 2 s. com*/
        EjercicioPK key = new EjercicioPK(id, ambiente.obtieneUsuario().getEmpresa().getOrganizacion());
        String nombre = ejercicioDao.elimina(key);

        redirectAttributes.addFlashAttribute("message", "ejercicio.eliminado.message");
        redirectAttributes.addFlashAttribute("messageAttrs", new String[] { nombre });
    } catch (Exception e) {
        log.error("No se pudo eliminar la ejercicio " + id, e);
        bindingResult.addError(
                new ObjectError("ejercicio", new String[] { "ejercicio.no.eliminado.message" }, null, null));
        return "contabilidad/ejercicio/ver/" + id;
    }

    return "redirect:/contabilidad/ejercicio";
}

From source file:com.xyxy.platform.web.account.ProfileController.java

@RequestMapping(method = RequestMethod.POST)
public String update(@Valid @ModelAttribute("user") User user, RedirectAttributes redirectAttributes,
        HttpServletRequest request) {/*from  w ww  .j  ava  2 s. com*/
    ShiroDbRealm.ShiroUser shiroUser = (ShiroDbRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
    accountService.updateUser(user, shiroUser.id);
    updateCurrentUserName(user.getLoginName());
    String msg = I18nMessageUtil.get(request, "profile.update.success", user.getLoginName());
    redirectAttributes.addFlashAttribute("message", msg);
    return "redirect:/profile";
}

From source file:controllers.admin.PostController.java

@PostMapping("/save")
public String processPost(@RequestPart("postImage") MultipartFile postImage,
        @ModelAttribute(ATTRIBUTE_NAME) @Valid Post post, BindingResult bindingResult,
        @CurrentUserAttached User activeUser, RedirectAttributes model) throws IOException, SQLException {

    String url = "redirect:/admin/posts/all";

    if (post.getImage() == null && postImage != null && postImage.isEmpty()) {
        bindingResult.rejectValue("image", "post.image.notnull");
    }/*w  w  w . j  a  v  a2 s. c  o m*/

    if (bindingResult.hasErrors()) {
        model.addFlashAttribute(BINDING_RESULT_NAME, bindingResult);
        return url;
    }

    if (postImage != null && !postImage.isEmpty()) {
        logger.info("Aadiendo informacin de la imagen");
        FileImage image = new FileImage();
        image.setName(postImage.getName());
        image.setContentType(postImage.getContentType());
        image.setSize(postImage.getSize());
        image.setContent(postImage.getBytes());
        post.setImage(image);
    }

    post.setAuthor(activeUser);
    if (post.getId() == null) {
        postService.create(post);
    } else {
        postService.edit(post);
    }

    List<String> successMessages = new ArrayList();
    successMessages.add(messageSource.getMessage("message.post.save.success", new Object[] { post.getId() },
            Locale.getDefault()));
    model.addFlashAttribute("successFlashMessages", successMessages);
    return url;
}