List of usage examples for org.springframework.web.servlet.mvc.support RedirectAttributes addAttribute
@Override RedirectAttributes addAttribute(String attributeName, @Nullable Object attributeValue);
From source file:me.doshou.admin.maintain.editor.web.controller.OnlineEditorController.java
@RequestMapping("move") public String move(@RequestParam(value = "descPath") String descPath, @RequestParam(value = "paths") String[] paths, @RequestParam(value = "conflict") String conflict, RedirectAttributes redirectAttributes) throws IOException { String rootPath = sc.getRealPath(ROOT_DIR); descPath = URLDecoder.decode(descPath, Constants.ENCODING); for (int i = 0, l = paths.length; i < l; i++) { String path = paths[i];//from w w w. ja va 2s. c om path = URLDecoder.decode(path, Constants.ENCODING); paths[i] = (rootPath + File.separator + path).replace("\\", "/"); } try { File descPathFile = new File(rootPath + File.separator + descPath); for (String path : paths) { File sourceFile = new File(path); File descFile = new File(descPathFile, sourceFile.getName()); if (descFile.exists() && "ignore".equals(conflict)) { continue; } FileUtils.deleteQuietly(descFile); if (sourceFile.isDirectory()) { FileUtils.moveDirectoryToDirectory(sourceFile, descPathFile, true); } else { FileUtils.moveFileToDirectory(sourceFile, descPathFile, true); } } redirectAttributes.addFlashAttribute(Constants.MESSAGE, "??"); } catch (Exception e) { redirectAttributes.addFlashAttribute(Constants.ERROR, e.getMessage()); } redirectAttributes.addAttribute("path", URLEncoder.encode(descPath, Constants.ENCODING)); return redirectToUrl(viewName("list")); }
From source file:org.opentravel.pubs.controllers.AdminController.java
@RequestMapping({ "/DoUpdateCodeList.html", "/DoUpdateCodeList.htm" }) public String doUpdateCodeListPage(HttpSession session, Model model, RedirectAttributes redirectAttrs, @ModelAttribute("codeListForm") CodeListForm codeListForm, @RequestParam(value = "archiveFile", required = false) MultipartFile archiveFile) { String targetPage = "updateSpecification"; try {// ww w . ja v a 2 s. c om if (codeListForm.isProcessForm()) { CodeListDAO cDao = DAOFactoryManager.getFactory().newCodeListDAO(); CodeList codeList = cDao.getCodeList(codeListForm.getCodeListId()); try { codeList.setReleaseDate(CodeList.labelFormat.parse(codeListForm.getReleaseDateLabel())); ValidationResults vResults = ModelValidator.validate(codeList); // Before we try to update the contents of the spefication, validate the // publication object to see if there are any errors. if (vResults.hasViolations()) { throw new ValidationException(vResults); } if (!archiveFile.isEmpty()) { cDao.updateCodeList(codeList, archiveFile.getInputStream()); } model.asMap().clear(); redirectAttrs.addAttribute("releaseDate", codeList.getReleaseDateLabel()); targetPage = "redirect:/admin/ViewCodeList.html"; } catch (ParseException e) { ValidationResults vResult = new ValidationResults(); vResult.add(codeList, "releaseDate", "Invalid release date"); addValidationErrors(vResult, model); } catch (ValidationException e) { addValidationErrors(e, model); } catch (Throwable t) { log.error("An error occurred while updating the spec: ", t); setErrorMessage(t.getMessage(), model); } } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:org.opentravel.pubs.controllers.AdminController.java
@RequestMapping({ "/DoUpdateSpecification.html", "/DoUpdateSpecification.htm" }) public String doUpdateSpecificationPage(HttpSession session, Model model, RedirectAttributes redirectAttrs, @ModelAttribute("specificationForm") SpecificationForm specificationForm, @RequestParam(value = "archiveFile", required = false) MultipartFile archiveFile) { String targetPage = "updateSpecification"; try {//from w w w.ja v a2s .c o m if (specificationForm.isProcessForm()) { PublicationDAO pDao = DAOFactoryManager.getFactory().newPublicationDAO(); Publication publication = pDao.getPublication(specificationForm.getPublicationId()); PublicationType publicationType = resolvePublicationType(specificationForm.getSpecType()); PublicationState publicationState = (specificationForm.getPubState() == null) ? null : PublicationState.valueOf(specificationForm.getPubState()); publication.setName(StringUtils.trimString(specificationForm.getName())); publication.setType(publicationType); publication.setState(publicationState); try { ValidationResults vResults = ModelValidator.validate(publication); // Before we try to update the contents of the spefication, validate the // publication object to see if there are any errors. if (vResults.hasViolations()) { throw new ValidationException(vResults); } if (!archiveFile.isEmpty()) { pDao.updateSpecification(publication, archiveFile.getInputStream()); } model.asMap().clear(); redirectAttrs.addAttribute("publication", publication.getName()); redirectAttrs.addAttribute("specType", publication.getType()); targetPage = "redirect:/admin/ViewSpecification.html"; } catch (ValidationException e) { addValidationErrors(e, model); } catch (Throwable t) { log.error("An error occurred while updating the spec: ", t); setErrorMessage(t.getMessage(), model); } } } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:mvc.OrderController.java
/** * ? ? //from w w w . j av a 2 s . co m * * @param model * @param dateFrom * @param dateTo * @param ra * @return */ @RequestMapping("/unloadMultipleInShop") public String unloadMultipleInShop(Map<String, Object> model, @RequestParam("dateFrom") Date dateFrom, @RequestParam("dateTo") Date dateTo, RedirectAttributes ra) { orderService.unloadMultipleInShop(dateFrom, dateTo); DateFormatter formatter = new DateFormatter(); ra.addAttribute("dateFrom", formatter.date(dateFrom)); ra.addAttribute("dateTo", formatter.date(dateTo)); return "redirect:/Order/reportForUnloadInShop"; }
From source file:org.opentravel.pubs.controllers.PublicationController.java
/** * Performs a download of the publication or publication item content specified by the URL * parameters.//ww w. ja v a 2 s . co m * * @param model the UI model for the current request * @param session the HTTP session * @param registrant the web site registrant who is performing the download * @param request the HTTP request for the content download * @param response the HTTP response to which output should be directed * @param redirectAttrs request attributes that must be available in case of a page redirect * @param releaseDateStr the release date of the code list archive being downloaded * @param filename the name of the content item that is being downloaded * @return String * @throws DAOException thrown if an error occurs while accessing the content from persistent storage * @throws IOException thrown if the content cannot be streamed to the HTTP response */ protected String doCodeListDownload(Model model, HttpSession session, Registrant registrant, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttrs, String releaseDateStr, String filename) throws DAOException, IOException { InputStream contentStream = null; String targetPath = null; if ((releaseDateStr != null) && (releaseDateStr.trim().length() > 0)) { CodeListDAO cDao = DAOFactoryManager.getFactory().newCodeListDAO(); DownloadDAO dDao = DAOFactoryManager.getFactory().newDownloadDAO(); try { CodeList codeList = cDao.getCodeList(CodeList.labelFormat.parse(releaseDateStr)); if (codeList != null) { if (filename.equals(codeList.getArchiveFilename())) { contentStream = dDao.getArchiveContent(codeList, registrant); } } } catch (ParseException e) { log.warn("Unreadable release date specified for code list download: \"" + releaseDateStr + "\""); } } if (contentStream != null) { try (OutputStream responseOut = response.getOutputStream()) { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = contentStream.read(buffer, 0, buffer.length)) >= 0) { responseOut.write(buffer, 0, bytesRead); } } finally { try { contentStream.close(); } catch (Throwable t) { } } } else { model.asMap().clear(); redirectAttrs.addAttribute("filename", request.getRequestURL()); targetPath = "redirect:/specifications/DownloadNotFound.html"; } return targetPath; }
From source file:org.opentravel.pubs.controllers.PublicationController.java
/** * Hanldes the processing for all of the schema comment page targets. * //w w w .ja va2 s .co m * @param model the UI model for the current request * @param session the HTTP session * @param redirectAttrs request attributes that must be available in case of a page redirect * @param newSession flag indicating that the user has requested to re-register in their session * @param commentForm the form used to supply the field values for the submitted comment * @param pubType the type of the publication to view (1.0/2.0) * @param isMembersOnlyPage flag indicating whether the page being viewed is a members-only page * @param targetPage the MVC name of the target page * @param submitCommentsUrl the URL location of the comment submission page * @return String */ private String doCommentSpecPage(Model model, HttpSession session, RedirectAttributes redirectAttrs, boolean newSession, SchemaCommentForm commentForm, PublicationType pubType, boolean isMembersOnlyPage, String targetPage, String submitCommentsUrl) { boolean commentSuccess = false; try { if (newSession) session.removeAttribute("registrantId"); Registrant registrant = getCurrentRegistrant(session); boolean processRegistrant = commentForm.isProcessForm() && (registrant == null); RegistrantForm registrantForm = commentForm.getRegistrantForm(); registrantForm.setProcessForm(processRegistrant); handleRegistrantInfo(registrantForm, model, session); registrant = (Registrant) model.asMap().get("registrant"); // If the registrant was created successfully, commit it and start a new // transaction for the comment if (processRegistrant && (registrant != null)) { DAOFactoryManager.getFactory().commitTransaction(); DAOFactoryManager.getFactory().beginTransaction(); registrant = getCurrentRegistrant(session); } if (commentForm.isProcessForm()) { commentSuccess = addSchemaComment(commentForm, registrant, model, session); } if (commentSuccess) { if (isMembersOnlyPage) { targetPage = "redirect:/specifications/members/CommentThankYou.html"; } else { targetPage = "redirect:/specifications/CommentThankYou.html"; } redirectAttrs.addAttribute("submitCommentsUrl", submitCommentsUrl); model.asMap().clear(); } else { PublicationDAO pDao = DAOFactoryManager.getFactory().newPublicationDAO(); Publication publication = pDao.getLatestPublication(pubType, getAllowedStates(isMembersOnlyPage)); List<PublicationItem> publicationItems = new ArrayList<>(); if (publication != null) { publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.WSDL)); publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.XML_SCHEMA)); publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.JSON_SCHEMA)); } model.addAttribute("publication", publication); model.addAttribute("publicationItems", publicationItems); model.addAttribute("commentTypes", Arrays.asList(CommentType.values())); setupPublicationCheck(model, isMembersOnlyPage, pubType); } model.addAttribute("submitCommentsUrl", submitCommentsUrl); commentForm.setProcessForm(true); } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:org.opentravel.pubs.controllers.PublicationController.java
/** * Hanldes the processing for all of the artifact comment page targets. * //from w ww. j a v a 2 s . c om * @param model the UI model for the current request * @param session the HTTP session * @param redirectAttrs request attributes that must be available in case of a page redirect * @param newSession flag indicating that the user has requested to re-register in their session * @param commentForm the form used to supply the field values for the submitted comment * @param pubType the type of the publication to view (1.0/2.0) * @param isMembersOnlyPage flag indicating whether the page being viewed is a members-only page * @param targetPage the MVC name of the target page * @param submitCommentsUrl the URL location of the comment submission page * @return String */ private String doCommentArtifactPage(Model model, HttpSession session, RedirectAttributes redirectAttrs, boolean newSession, ArtifactCommentForm commentForm, PublicationType pubType, boolean isMembersOnlyPage, String targetPage, String submitCommentsUrl) { boolean commentSuccess = false; try { if (newSession) session.removeAttribute("registrantId"); Registrant registrant = getCurrentRegistrant(session); boolean processRegistrant = commentForm.isProcessForm() && (registrant == null); RegistrantForm registrantForm = commentForm.getRegistrantForm(); registrantForm.setProcessForm(processRegistrant); handleRegistrantInfo(registrantForm, model, session); registrant = (Registrant) model.asMap().get("registrant"); // If the registrant was created successfully, commit it and start a new // transaction for the comment if (processRegistrant && (registrant != null)) { DAOFactoryManager.getFactory().commitTransaction(); DAOFactoryManager.getFactory().beginTransaction(); registrant = getCurrentRegistrant(session); } if (commentForm.isProcessForm()) { commentSuccess = addArtifactComment(commentForm, registrant, model, session); } if (commentSuccess) { if (isMembersOnlyPage) { targetPage = "redirect:/specifications/members/CommentThankYou.html"; } else { targetPage = "redirect:/specifications/CommentThankYou.html"; } redirectAttrs.addAttribute("submitCommentsUrl", submitCommentsUrl); model.asMap().clear(); } else { PublicationDAO pDao = DAOFactoryManager.getFactory().newPublicationDAO(); Publication publication = pDao.getLatestPublication(pubType, getAllowedStates(isMembersOnlyPage)); List<PublicationItem> publicationItems = new ArrayList<>(); if (publication != null) { publicationItems.addAll(pDao.getPublicationItems(publication, PublicationItemType.ARTIFACT)); } model.addAttribute("publication", publication); model.addAttribute("publicationItems", publicationItems); model.addAttribute("commentTypes", Arrays.asList(CommentType.values())); setupPublicationCheck(model, isMembersOnlyPage, pubType); } model.addAttribute("submitCommentsUrl", submitCommentsUrl); commentForm.setProcessForm(true); } catch (Throwable t) { log.error("Error during publication controller processing.", t); setErrorMessage(DEFAULT_ERROR_MESSAGE, model); } return applyCommonValues(model, targetPage); }
From source file:org.opentravel.pubs.controllers.PublicationController.java
/** * Performs a download of the publication or publication item content specified by the URL * parameters./*from w ww . j av a2s . c o m*/ * * @param model the UI model for the current request * @param session the HTTP session * @param registrant the web site registrant who is performing the download * @param request the HTTP request for the content download * @param response the HTTP response to which output should be directed * @param redirectAttrs request attributes that must be available in case of a page redirect * @param pubName the name of the publication from which content is being downloaded * @param type the type of the publication * @param filename the name of the content item that is being downloaded * @return String * @throws DAOException thrown if an error occurs while accessing the content from persistent storage * @throws IOException thrown if the content cannot be streamed to the HTTP response */ protected String doPublicationDownload(Model model, HttpSession session, Registrant registrant, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttrs, String pubName, String type, String filename) throws DAOException, IOException { InputStream contentStream = null; String targetPath = null; if ((pubName != null) && (type != null) && (filename != null)) { PublicationDAO pDao = DAOFactoryManager.getFactory().newPublicationDAO(); DownloadDAO dDao = DAOFactoryManager.getFactory().newDownloadDAO(); PublicationType pubType = resolvePublicationType(type); Publication publication = pDao.getPublication(pubName, pubType); if (publication != null) { if (filename.equals(publication.getArchiveFilename())) { contentStream = dDao.getArchiveContent(publication, registrant); } else { PublicationItem item = pDao.findPublicationItem(publication, filename); if (item != null) { contentStream = dDao.getContent(item, registrant); } } } } if (contentStream != null) { try (OutputStream responseOut = response.getOutputStream()) { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = contentStream.read(buffer, 0, buffer.length)) >= 0) { responseOut.write(buffer, 0, bytesRead); } } finally { try { contentStream.close(); } catch (Throwable t) { } } } else { model.asMap().clear(); redirectAttrs.addAttribute("filename", request.getRequestURL()); targetPath = "redirect:/specifications/DownloadNotFound.html"; } return targetPath; }
From source file:np.com.drose.studentmanagementsystem.controller.ProjectController.java
@RequestMapping(value = "/admin/project/edit/{id}", method = RequestMethod.POST) public RedirectView updateProject(@Valid @ModelAttribute("project") Project project, BindingResult result, RedirectAttributes redirectAttr, Model model) { RedirectView redirectView = new RedirectView(); try {// w ww .java 2 s. c om if (result.hasErrors()) { redirectAttr.addAttribute("editProject", result); redirectAttr.addFlashAttribute("errorMessage", "unable to update due to null value " + project.getProjectName()); redirectView.setContextRelative(true); redirectView.setUrl("/admin/project/edit/{id}"); return redirectView; } projectService.updateRow(project); redirectAttr.addFlashAttribute("message", "Successful update"); } catch (Exception e) { log.info("error in updating" + e); } redirectView.setContextRelative(true); redirectView.setUrl("/both/project/project/list"); return redirectView; }
From source file:org.jbb.system.web.logging.controller.AcpLoggerController.java
@RequestMapping(method = RequestMethod.POST) public String loggerPost(@ModelAttribute(LOGGER_FORM) LoggerForm form, Model model, BindingResult bindingResult, RedirectAttributes redirectAttributes) { AppLogger appLogger = new AppLogger(); appLogger.setName(form.getName());/*from ww w . j a va 2 s . c o m*/ appLogger.setAddivity(form.isAddivity()); appLogger.setLevel(LogLevel.valueOf(form.getLevel().toUpperCase())); appLogger.setAppenders(getLogAppenders(form)); try { if (form.isAddingMode()) { loggingSettingsService.addLogger(appLogger); } else { loggingSettingsService.updateLogger(appLogger); } redirectAttributes.addFlashAttribute(FORM_SAVED_FLAG, true); } catch (LoggingConfigurationException e) { log.debug("Logger {} validation error", appLogger, e); errorsBindingMapper.map(e.getConstraintViolations(), bindingResult); model.addAttribute(FORM_SAVED_FLAG, false); model.addAttribute(LOGGER_FORM, form); model.addAttribute(NEW_LOGGER_STATE, form.isAddingMode()); putLoggingLevelsToModel(model); LoggingConfiguration loggingConfiguration = loggingSettingsService.getLoggingConfiguration(); AppLogger logger = new AppLogger(); logger.setName(form.getName()); form.setAppenders(prepareAppendersMap(loggingConfiguration, logger)); return VIEW_NAME; } redirectAttributes.addAttribute("act", "edit"); redirectAttributes.addAttribute("id", appLogger.getName()); return "redirect:/acp/general/logging/logger"; }