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:com.oakhole.auth.web.FileController.java

/**
 * webopen office?//from   w w w  .j a va  2  s .co  m
 *
 * @param file
 * @param redirectAttributes
 * @return
 */
@RequestMapping(value = "update", method = RequestMethod.POST)
public String update(@Valid @ModelAttribute(value = "file") File file, RedirectAttributes redirectAttributes) {
    this.fileService.save(file);
    redirectAttributes.addFlashAttribute("message", "?");
    redirectAttributes.addFlashAttribute("returnStatus", "success");
    return "redirect:/file";
}

From source file:com.diguage.wanwan.web.task.TaskController.java

@RequestMapping(value = "create", method = RequestMethod.POST)
public String create(@Valid Task newTask, RedirectAttributes redirectAttributes) {
    User user = new User();
    user.setId(getCurrentUserId());//  w w w.j a  v a  2  s.  c o  m
    newTask.setUserId(user.getId());

    taskService.saveTask(newTask);
    redirectAttributes.addFlashAttribute("message", "?");
    return "redirect:/task/";
}

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

@RequestMapping(value = "/instructor/exercises/{exerciseId}/edit", method = RequestMethod.POST, params = "delete")
@PreAuthorize("@instructorSecurity.hasAccessToExercise(authentication.name, #exerciseId)")
public String delete(Model model, @PathVariable int exerciseId, RedirectAttributes redirectAttributes) {
    try {//from   ww  w . j  a v  a  2  s.c o m
        exerciseRepo.delete(exerciseId);
    } catch (ForbiddenException e) {
        redirectAttributes.addFlashAttribute("errorMessageCode", "cantDeleteExercise");
        return "redirect:/instructor/exercises/{exerciseId}/edit";
    }

    redirectAttributes.addFlashAttribute("okMessageCode", "exerciseDeleted");
    return "redirect:/instructor";
}

From source file:net.sf.sze.frontend.zeugnis.PdfController.java

/**
 * Erstellt das PDF fr eine Klasse./*from   ww w.  j av a  2s  . c  o m*/
 * @param halbjahr das Schulhalbjahr.
 * @param klasse die Klasse
 * @param isRemoteCall true wenn die Anfrage remote erfolgt.
 * @param redirectAttributes die Meldungen.
 * @return die logische View
 */
@RequestMapping(value = URL.Zeugnis.ALL_PDFS, method = RequestMethod.GET)
public View createAllPDFS(@RequestParam(URL.Session.P_HALBJAHR_ID) Schulhalbjahr halbjahr,
        @RequestParam(URL.Session.P_KLASSEN_ID) Klasse klasse,
        @ModelAttribute(MODELL_ATTRIBUTE_IS_REMOTE_CALL) boolean isRemoteCall,
        RedirectAttributes redirectAttributes) {
    final File zeugnisDatei = zeugnisCreatorService.createZeugnisse(halbjahr, klasse);
    if (zeugnisDatei == null) {
        redirectAttributes.addFlashAttribute(MESSAGE, "Es sind keine Zeugnisse vorhanden.");
    } else if (zeugnisDatei.exists() && zeugnisDatei.canRead()) {
        final Subject currentUser = SecurityUtils.getSubject();
        if (!isRemoteCall || currentUser.isPermitted("print:remoteAll")) {
            return new FileContentView(zeugnisDatei, "Klasse_" + klasse.calculateKlassenname() + ".pdf");
        } else {
            redirectAttributes.addFlashAttribute(MESSAGE, "Zeugnisse wurden erstellt, "
                    + "aber Sie sind nicht berechtigt diese im Browser anzusehen.");
            LOG.info(zeugnisDatei.getAbsolutePath() + " wurde angelegt, aber "
                    + "mangels Berechtigung nicht an {} ausgeliefert.", currentUser.getPrincipal());
        }
    } else {
        redirectAttributes.addFlashAttribute(MESSAGE, "Zeugnis erstellt, aber nicht lesbar.");
        LOG.warn("Kann " + zeugnisDatei.getAbsolutePath() + " nicht lesen. " + "Exists: "
                + zeugnisDatei.exists() + ", canRead: " + zeugnisDatei.canRead());
    }
    return new RedirectView(URL.filledURLWithNamedParams(URL.ZeugnisPath.START, URL.Session.P_HALBJAHR_ID,
            halbjahr.getId(), URL.Session.P_KLASSEN_ID, klasse.getId()), true);
}

From source file:wad.booklibrary.controller.BookController.java

@RequestMapping(value = "bookform/new", method = RequestMethod.POST)
public String create(@Valid @ModelAttribute(value = "book") Book book, BindingResult bindingResult,
        RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        return "bookform";
    }// w ww. ja v a  2  s. com
    bookService.create(book);
    redirectAttributes.addFlashAttribute("message", "New book created!");
    return "redirect:/app/bookform";
}

From source file:aiai.ai.launchpad.resource.ResourceController.java

@GetMapping("/resource-delete/{id}")
public String delete(@PathVariable Long id, Model model, final RedirectAttributes redirectAttributes) {
    final BinaryData data = binaryDataService.findById(id).orElse(null);
    if (data == null) {
        redirectAttributes.addFlashAttribute("errorMessage", "#172.10 Resource wasn't found for id: " + id);
        return "redirect:/launchpad/resources";
    }//ww  w  .j  a  va 2 s. c om
    model.addAttribute("resource", data);
    return "launchpad/resource-delete";
}

From source file:aiai.ai.launchpad.resource.ResourceController.java

@PostMapping("/resource-delete-commit")
public String deleteResource(Long id, final RedirectAttributes redirectAttributes) {
    final BinaryData data = binaryDataService.findById(id).orElse(null);
    if (data == null) {
        redirectAttributes.addFlashAttribute("errorMessage", "#172.20 Resource wasn't found for id: " + id);
        return "redirect:/launchpad/resources";
    }/*from   w  w w  .j a  va 2s  .  co  m*/
    binaryDataService.deleteById(id);
    return "redirect:/launchpad/resources";
}

From source file:aiai.ai.launchpad.snippet.SnippetController.java

@PostMapping(value = "/snippet-upload-from-file")
public String uploadSnippet(MultipartFile file, final RedirectAttributes redirectAttributes) {

    String originFilename = file.getOriginalFilename();
    if (originFilename == null) {
        redirectAttributes.addFlashAttribute("errorMessage", "#422.01 name of uploaded file is null");
        return "redirect:/launchpad/snippets";
    }//from  w  ww. j  av  a 2 s.  c  o m
    int idx;
    if ((idx = originFilename.lastIndexOf('.')) == -1) {
        redirectAttributes.addFlashAttribute("errorMessage",
                "#422.02 '.' wasn't found, bad filename: " + originFilename);
        return "redirect:/launchpad/snippets";
    }
    String ext = originFilename.substring(idx).toLowerCase();
    if (!".zip".equals(ext)) {
        redirectAttributes.addFlashAttribute("errorMessage",
                "#422.03 only '.zip' files is supported, filename: " + originFilename);
        return "redirect:/launchpad/snippets";
    }

    final String location = System.getProperty("java.io.tmpdir");

    try {
        File tempDir = DirUtils.createTempDir("snippet-upload-");
        if (tempDir == null || tempDir.isFile()) {
            redirectAttributes.addFlashAttribute("errorMessage",
                    "#422.04 can't create temporary directory in " + location);
            return "redirect:/launchpad/snippets";
        }
        final File zipFile = new File(tempDir, "snippet.zip");
        log.debug("Start storing an uploaded snippet to disk");
        try (OutputStream os = new FileOutputStream(zipFile)) {
            IOUtils.copy(file.getInputStream(), os, 64000);
        }
        log.debug("Start unzipping archive");
        ZipUtils.unzipFolder(zipFile, tempDir);
        log.debug("Start loading snippet data to db");
        snippetService.loadSnippetsRecursively(tempDir);
    } catch (Exception e) {
        log.error("Error", e);
        redirectAttributes.addFlashAttribute("errorMessage",
                "#422.05 can't load snippets, Error: " + e.toString());
        return "redirect:/launchpad/snippets";
    }

    log.debug("All done. Send redirect");
    return "redirect:/launchpad/snippets";
}

From source file:com.nicodewet.web.SubscribeController.java

@RequestMapping(value = "/subscribeth", method = RequestMethod.POST)
public String subscribe(@Valid final Subscription subscription, final BindingResult bindingResult,
        final ModelMap model, RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        return "subscribeth";
    } else {//from ww  w . j a v a 2s . co m
        logger.info("JUST ADDED SUBSCRIPTION: " + subscription);
        model.clear();
        redirectAttributes.addFlashAttribute("subscribed", "success");
        return "redirect:/subscribeth";
    }
}

From source file:io.manasobi.license.LicenseController.java

@RequestMapping(value = "/publish", method = RequestMethod.POST)
public String publish(License license, RedirectAttributes redirectAttributes, Principal principal) {

    Result result = Result.EMPTY;

    result = licenseService.sendJobTicket(license);

    redirectAttributes.addFlashAttribute("licenseGenKey", license.getId());

    if (result == Result.ERROR_102001) {
        redirectAttributes.addFlashAttribute("error", result.getMessage());
    }/*w  w  w . j av  a2  s.c om*/

    String userName = principal == null ? "" : principal.getName();

    result = licenseService.saveLicenseDetails(userName, license);

    return "redirect:/license/publish/result";
}