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(Object attributeValue);

Source Link

Document

Add the given flash storage using a org.springframework.core.Conventions#getVariableName generated name .

Usage

From source file:cherry.sqlman.tool.load.SqlLoadControllerImpl.java

@Override
public ModelAndView execute(SqlLoadForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, NativeWebRequest request, RedirectAttributes redirAttr) {

    if (hasErrors(form, binding)) {
        return withViewname(viewnameOfStart).build();
    }/*from  ww  w  .  ja v a2  s.  co m*/

    try {

        FileProcessResult result = handleFile(form.getFile(), form.getDatabaseName(), form.getSql());
        redirAttr.addFlashAttribute(result);
        form.setFile(null);

        return redirect(redirectOnExecute()).build();
    } catch (BadSqlGrammarException ex) {
        LogicalErrorUtil.reject(binding, LogicError.BadSqlGrammer, Util.getRootCause(ex).getMessage());
        return withViewname(viewnameOfStart).build();
    }
}

From source file:com.example.todo.app.todo.TodoController.java

@RequestMapping(value = "finish", method = RequestMethod.POST)
public String finish(@Validated({ Default.class, TodoFinish.class }) TodoForm form, BindingResult bindingResult,
        Model model, RedirectAttributes attributes) {
    if (bindingResult.hasErrors()) {
        return list(model);
    }/* w w  w.j  a  v  a2s. c  om*/

    try {
        todoService.finish(form.getTodoId());
    } catch (BusinessException e) {
        model.addAttribute(e.getResultMessages());
        return list(model);
    }

    attributes
            .addFlashAttribute(ResultMessages.success().add(ResultMessage.fromText("Finished successfully!")));
    return "redirect:/todo/list";
}

From source file:com.example.todo.app.todo.TodoController.java

@RequestMapping(value = "delete", method = RequestMethod.POST) // (1)
public String delete(@Validated({ Default.class, TodoDelete.class }) TodoForm form, BindingResult bindingResult,
        Model model, RedirectAttributes attributes) {

    if (bindingResult.hasErrors()) {
        return list(model);
    }//w ww  .  j a v a 2  s. c  o m

    try {
        todoService.delete(form.getTodoId());
    } catch (BusinessException e) {
        model.addAttribute(e.getResultMessages());
        return list(model);
    }

    attributes.addFlashAttribute(ResultMessages.success().add(ResultMessage.fromText("Deleted successfully!")));
    return "redirect:/todo/list";
}

From source file:cherry.sqlman.tool.load.SqlLoadIdControllerImpl.java

@Override
public ModelAndView execute(int id, SqlLoadForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, NativeWebRequest request, RedirectAttributes redirAttr) {

    if (hasErrors(form, binding)) {
        return withViewname(viewnameOfStart).build();
    }/*from w w  w .j  a  va 2 s.com*/

    try {

        FileProcessResult result = handleFile(form.getFile(), form.getDatabaseName(), form.getSql());
        redirAttr.addFlashAttribute(result);
        form.setFile(null);

        return redirect(redirectOnExecute(id)).build();
    } catch (BadSqlGrammarException ex) {
        LogicalErrorUtil.reject(binding, LogicError.BadSqlGrammer, Util.getRootCause(ex).getMessage());
        return withViewname(viewnameOfStart).build();
    }
}

From source file:com.example.todo.app.todo.TodoController.java

@RequestMapping(value = "create", method = RequestMethod.POST)
public String create(@Validated({ Default.class, TodoCreate.class }) TodoForm todoForm,
        BindingResult bindingResult, Model model, RedirectAttributes attributes) {

    if (bindingResult.hasErrors()) {
        return list(model);
    }/*from ww  w . ja  v a2 s .  c  o m*/

    Todo todo = beanMapper.map(todoForm, Todo.class);

    try {
        todoService.create(todo);
    } catch (BusinessException e) {
        model.addAttribute(e.getResultMessages());
        return list(model);
    }

    attributes.addFlashAttribute(ResultMessages.success().add(ResultMessage.fromText("Created successfully!")));
    return "redirect:/todo/list";
}