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.gob.cfe.documentos.web.DocumentoController.java

@RequestMapping("/elimina/{id}")
public String elimina(@PathVariable Long id, Model model, RedirectAttributes redirectAttributes) {
    String titulo = instance.elimina(id);
    redirectAttributes.addFlashAttribute("mensaje", "Se elimino el documento " + titulo);
    return "redirect:/documento";
}

From source file:cz.muni.pa165.carparkapp.web.LoansController.java

@RequestMapping(value = "/return/{id}", method = RequestMethod.POST)
public String update(@PathVariable int id, UriComponentsBuilder uriBuilder,
        RedirectAttributes redirectAttributes, Locale locale) {
    LoanDTO loan = loanService.getLoanById(id);
    log.debug("update(locale={}, loan={})", locale, loan);
    Date date = new Date();
    loan.setEndDate(date);//from  w w  w .j a v a 2  s  .  c  om
    loanService.updateLoan(loan);
    redirectAttributes.addFlashAttribute("message",
            messageSource.getMessage("loan.returned", new Object[] { loan.getCar().getId() }, locale));
    return "redirect:" + uriBuilder.path("/loans").build();
}

From source file:com.aerospike.controller.ClientController.java

@RequestMapping(value = "/", method = RequestMethod.POST)
public String runBenchmark(@Valid WorkloadConfig newConfig, BindingResult bindingResult,
        RedirectAttributes redirectAttributes, @RequestParam(value = "action", required = true) String action) {

    if (bindingResult.hasErrors()) {
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.workloadConfig",
                bindingResult);//w ww.ja v a  2  s  . c  om
        redirectAttributes.addFlashAttribute("workloadConfig", newConfig);
        return "redirect:/";
    }
    this.workloadConfig = newConfig;
    this.workloads.put(newConfig.getResourcename(), newConfig);

    Properties properties = newConfig.toProperties();
    com.aerospike.util.Exporter.stringArrayList.clear();
    if (services == null || services.size() == 0) {
        redirectAttributes.addFlashAttribute("error", "No services available!");
        return "redirect:/results";
    }

    try {
        if (action.equals("load")) {
            /* LOAD DATA FOR SERVICE */
            String args = "-s,-load,-p,exporter=com.aerospike.util.Exporter";

            IServiceConfiguration csf = services.get(this.serviceNameA);
            args += csf.getPropertyString();

            com.aerospike.util.Exporter.stringArrayList.clear();
            com.yahoo.ycsb.Client.webMain(args.split(","), properties);
            results = new ArrayList<String[]>(com.aerospike.util.Exporter.stringArrayList);
        } else if (action.equals("run")) {
            /* RUN  SERVICE */
            String args = "-t,-p,exporter=com.aerospike.util.Exporter";
            IServiceConfiguration csf = services.get(this.serviceNameA);
            args += csf.getPropertyString();

            com.aerospike.util.Exporter.stringArrayList.clear();
            com.yahoo.ycsb.Client.webMain(args.split(","), properties);
            results = new ArrayList<String[]>(com.aerospike.util.Exporter.stringArrayList);
        } else {
            redirectAttributes.addFlashAttribute("error", "Invalid action for run command");
            return "redirect:/";
        }
    } catch (Exception e) {
        System.out.println("ERROR: " + e.getMessage());
        redirectAttributes.addFlashAttribute("error", e.getMessage());
        return "redirect:/";
    }

    return "redirect:/results";
}

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

/**
 * Checks the existence of a dataset identified by the <code>datasetName</code> argument and deletes it if it
 * exists. Adds a success or error message to <code>redirectAttrs</code> depending on the outcome.
 * /* w  ww .j av  a  2  s .  c om*/
 * @param datasetName
 * @param redirectAttrs
 * @return a redirect link to the dataset home page
 */
@RequestMapping("/{datasetName}/delete")
public String deleteDataset(@PathVariable final String datasetName, final RedirectAttributes redirectAttrs) {
    if (datasetRepo.exists(datasetName)) {
        datasetRepo.delete(datasetName);

        LOG.info("Deleted dataset: [{}]", datasetName);

        redirectAttrs.addFlashAttribute("msgKey", "datasets.delete.succcess");
    } else {
        redirectAttrs.addFlashAttribute("errorKey", "datasets.delete.failure");
    }
    return "redirect:/datasets";
}

From source file:controllers.SceneController.java

@RequestMapping(value = "/delete")
public String delete(Map<String, Object> model, @RequestParam("sceneId") Long sceneId, RedirectAttributes ras)
        throws Exception {
    Scene s = sceneService.getScene(sceneId);
    if (s.getEvents().isEmpty()) {
        sceneService.delete(sceneId);//from   w  ww  . j  av a 2s .  c om
        ras.addFlashAttribute("error", sceneService.getResult().getErrors());
        return "redirect:/Scene/show";
    } else {
        String err = " ???  : ";
        for (Event ev : s.getEvents()) {
            err += ev.getId() + " - " + ev.getName() + "; ";
        }
        List<String> ers = sceneService.getResult().getErrors();
        ers.add(err);
        ras.addFlashAttribute("error", ers);
        return "redirect:/Scene/show";
    }
}

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

@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
public String delete(@PathVariable long id, Model model, UriComponentsBuilder uriBuilder,
        RedirectAttributes redirectAttributes) {
    GameDTO game = gameFacade.findById(id);
    gameFacade.delete(game);/*  www  .  j a va  2 s.co m*/
    log.debug("delete({})", id);
    redirectAttributes.addFlashAttribute("alert_success", "Game \"" + game.toString() + "\" was deleted.");
    return "redirect:" + uriBuilder.path("/game/list").toUriString();
}

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

@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("@instructorSecurity.hasAccessToWorksheet(authentication.name, #worksheetId)")
public String edit(@ModelAttribute Instructor instructor, @PathVariable int worksheetId, Model model,
        RedirectAttributes redirectAttributes) {
    ExerciseWorksheet worksheet = exerciseWorksheetRepo.getById(worksheetId);

    // unlocked worksheets can't be edited, redirect...
    if (worksheet.isUnlocked()) {
        redirectAttributes.addFlashAttribute("errorMessageCode", "exerciseWorksheetAlreadyUnlocked");
        return "redirect:/instructor/worksheets/{worksheetId}";
    }//from w  w w . j a v a  2 s .c  o m

    model.addAttribute("worksheet", worksheet);

    return "instructor/worksheetEditor";
}

From source file:org.wallride.web.controller.admin.user.UserInvitationCreateController.java

@RequestMapping(method = RequestMethod.POST)
public String save(@PathVariable String language, @Valid @ModelAttribute("form") UserInvitationCreateForm form,
        BindingResult result, String query, AuthorizedUser authorizedUser,
        RedirectAttributes redirectAttributes) throws MessagingException {
    if (result.hasErrors()) {
        return "user/invitation/index";
    }/*from   w  w  w.ja  v a2s.  com*/
    List<UserInvitation> invitations = userService.inviteUsers(form.buildUserInvitationCreateRequest(), result,
            authorizedUser);
    redirectAttributes.addFlashAttribute("savedInvitations", invitations);
    redirectAttributes.addAttribute("query", query);
    return "redirect:/_admin/{language}/users/invitations/index";
}

From source file:cz.swi2.mendeluis.app.web.controllers.PortletsController.java

/**
 * Remove the attached portlet from the current user. 
 *///from   w w  w  .  j a va  2s .  c o m
@PreAuthorize("hasPermission(#id, 'UserPortlet', 'isOwner')")
@RequestMapping(value = "remove/{id}", method = RequestMethod.GET)
public String remove(@PathVariable int id, RedirectAttributes redirectAttributes, Principal principal) {

    userPortletFacade.deleteUserPortlet(id);

    redirectAttributes.addFlashAttribute("alert_success", "Portlet was detached.");
    return "redirect:/portlets/";
}

From source file:me.doshou.admin.maintain.dynamictask.web.controller.DynamicTaskController.java

@RequestMapping(value = "batch/delete", method = { RequestMethod.GET, RequestMethod.POST })
public String deleteInBatch(@RequestParam(value = "forceTermination") boolean forceTermination,
        @RequestParam(value = "ids", required = false) Long[] ids,
        @RequestParam(value = Constants.BACK_URL, required = false) String backURL,
        RedirectAttributes redirectAttributes) {
    if (permissionList != null) {
        this.permissionList.assertHasDeletePermission();
    }//w  ww  .  j  av  a 2s.  c  o m

    dynamicTaskApi.deleteTaskDefinition(forceTermination, ids);

    redirectAttributes.addFlashAttribute(Constants.MESSAGE, "?");
    return redirectToUrl(backURL);
}