Java Code Examples for org.springframework.web.servlet.support.RequestContextUtils#getOutputFlashMap()
The following examples show how to use
org.springframework.web.servlet.support.RequestContextUtils#getOutputFlashMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JseErrorsTagTest.java From sinavi-jfw with Apache License 2.0 | 6 votes |
@Test public void エラーメッセージがリクエストとフラッシュスコープにセットされ出力される() throws Exception { MessageContext context = new MessageContext(request); context.saveErrorMessageToRequest("E-JX_ERRORS_TAG_TEST#0001"); context.saveErrorMessageToFlash("E-JX_ERRORS_TAG_TEST#0002"); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); request.setAttribute(MessageContext.ERROR_MESSAGE_KEY_TO_FLASH, flashMap.get(MessageContext.ERROR_MESSAGE_KEY_TO_FLASH)); JseErrorsTag tag = new JseErrorsTag(); tag.setJspContext(page); tag.doTag(); assertThat(response.getContentAsString(), is("<div class=\"jfw_messages\">" + "<p class=\"jfw_err_msg_style\">E-JX_ERRORS_TAG_TEST#0001</p>" + "<p class=\"jfw_err_msg_style\">E-JX_ERRORS_TAG_TEST#0002</p></div>")); }
Example 2
Source File: RedirectView.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Convert model to request parameters and redirect to the given URL. * @see #appendQueryProperties * @see #sendRedirect */ @Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws IOException { String targetUrl = createTargetUrl(model, request); targetUrl = updateTargetUrl(targetUrl, model, request, response); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (!CollectionUtils.isEmpty(flashMap)) { UriComponents uriComponents = UriComponentsBuilder.fromUriString(targetUrl).build(); flashMap.setTargetRequestPath(uriComponents.getPath()); flashMap.addTargetRequestParams(uriComponents.getQueryParams()); FlashMapManager flashMapManager = RequestContextUtils.getFlashMapManager(request); if (flashMapManager == null) { throw new IllegalStateException("FlashMapManager not found despite output FlashMap having been set"); } flashMapManager.saveOutputFlashMap(flashMap, request, response); } sendRedirect(request, response, targetUrl, this.http10Compatible); }
Example 3
Source File: JseInformationsTagTest.java From sinavi-jfw with Apache License 2.0 | 6 votes |
@Test public void インフォメーションメッセージがリクエストとフラッシュスコープにセットされ出力される() throws Exception { MessageContext context = new MessageContext(request); context.saveInformationMessageToRequest("I-JX_INFORMATIONS_TAG_TEST#0001"); context.saveInformationMessageToFlash("I-JX_INFORMATIONS_TAG_TEST#0002"); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); request.setAttribute(MessageContext.INFORMATION_MESSAGE_KEY_TO_FLASH, flashMap.get(MessageContext.INFORMATION_MESSAGE_KEY_TO_FLASH)); JseInformationsTag tag = new JseInformationsTag(); tag.setJspContext(page); tag.doTag(); assertThat(response.getContentAsString(), is("<div class=\"jfw_messages\">" + "<p class=\"jfw_msg_style\">I-JX_INFORMATIONS_TAG_TEST#0001</p>" + "<p class=\"jfw_msg_style\">I-JX_INFORMATIONS_TAG_TEST#0002</p></div>")); }
Example 4
Source File: RedirectView.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Convert model to request parameters and redirect to the given URL. * @see #appendQueryProperties * @see #sendRedirect */ @Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws IOException { String targetUrl = createTargetUrl(model, request); targetUrl = updateTargetUrl(targetUrl, model, request, response); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); if (!CollectionUtils.isEmpty(flashMap)) { UriComponents uriComponents = UriComponentsBuilder.fromUriString(targetUrl).build(); flashMap.setTargetRequestPath(uriComponents.getPath()); flashMap.addTargetRequestParams(uriComponents.getQueryParams()); FlashMapManager flashMapManager = RequestContextUtils.getFlashMapManager(request); if (flashMapManager == null) { throw new IllegalStateException("FlashMapManager not found despite output FlashMap having been set"); } flashMapManager.saveOutputFlashMap(flashMap, request, response); } sendRedirect(request, response, targetUrl, this.http10Compatible); }
Example 5
Source File: TagRestController.java From wallride with Apache License 2.0 | 6 votes |
@RequestMapping(value="/{language}/tags", method=RequestMethod.POST) public @ResponseBody DomainObjectSavedModel save( @Valid TagCreateForm form, BindingResult errors, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { if (errors.hasErrors()) { throw new BindException(errors); } Tag savedTag; try { savedTag = tagService.createTag(form.buildTagCreateRequest(), authorizedUser); } catch (DuplicateNameException e) { errors.rejectValue("name", "NotDuplicate"); throw new BindException(errors); } FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("savedTag", savedTag); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectSavedModel<>(savedTag); }
Example 6
Source File: TagRestController.java From wallride with Apache License 2.0 | 6 votes |
@RequestMapping(value="/{language}/tags/{id}", method=RequestMethod.POST) public @ResponseBody DomainObjectUpdatedModel update( @Valid TagEditForm form, BindingResult errors, @PathVariable long id, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { form.setId(id); if (errors.hasErrors()) { throw new BindException(errors); } Tag savedTag; try { savedTag = tagService.updateTag(form.buildTagUpdateRequest(), authorizedUser); } catch (DuplicateNameException e) { errors.rejectValue("name", "NotDuplicate"); throw new BindException(errors); } FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("savedTag", savedTag); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectUpdatedModel<>(savedTag); }
Example 7
Source File: TagRestController.java From wallride with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/{language}/tags/merge", method = RequestMethod.POST) public @ResponseBody DomainObjectSavedModel merge( @Valid TagMergeForm form, BindingResult errors, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { if (errors.hasErrors()) { throw new BindException(errors); } Tag mergedTag; try { mergedTag = tagService.mergeTags(form.toTagMergeRequest(), authorizedUser); } catch (DuplicateNameException e) { errors.rejectValue("name", "NotDuplicate"); throw new BindException(errors); } FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("mergedTag", mergedTag); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectSavedModel<>(mergedTag); }
Example 8
Source File: CategoryRestController.java From wallride with Apache License 2.0 | 6 votes |
@RequestMapping(value="/{language}/categories", method=RequestMethod.POST) public @ResponseBody DomainObjectSavedModel save( @Valid CategoryCreateForm form, BindingResult result, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { if (result.hasErrors()) { throw new BindException(result); } Category category = categoryService.createCategory(form.buildCategoryCreateRequest(), authorizedUser); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("savedCategory", category); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectSavedModel<>(category); }
Example 9
Source File: CategoryRestController.java From wallride with Apache License 2.0 | 6 votes |
@RequestMapping(value="/{language}/categories/{id}", method=RequestMethod.POST) public @ResponseBody DomainObjectUpdatedModel update( @Valid CategoryEditForm form, BindingResult result, @PathVariable long id, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { form.setId(id); if (result.hasErrors()) { throw new BindException(result); } Category category = categoryService.updateCategory(form.buildCategoryUpdateRequest(), authorizedUser); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("updatedCategory", category); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectUpdatedModel<>(category); }
Example 10
Source File: PageRestController.java From wallride with Apache License 2.0 | 6 votes |
@RequestMapping(value="/{language}/pages", method=RequestMethod.POST) public @ResponseBody DomainObjectSavedModel save( @Valid PageCreateForm form, BindingResult result, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { if (result.hasErrors()) { throw new BindException(result); } Page page = pageService.createPage(form.buildPageCreateRequest(), Post.Status.DRAFT, authorizedUser); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("savedPage", page); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectSavedModel<>(page); }
Example 11
Source File: JseErrorsTagTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
@Test public void インフォメーションメッセージがフラッシュスコープにセットされ出力されない() throws Exception { MessageContext context = new MessageContext(request); context.saveInformationMessageToFlash("I-JX_INFORMATIONS_TAG_TEST#0001"); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); request.setAttribute(MessageContext.INFORMATION_MESSAGE_KEY_TO_FLASH, flashMap.get(MessageContext.INFORMATION_MESSAGE_KEY_TO_FLASH)); JseErrorsTag tag = new JseErrorsTag(); tag.setJspContext(page); tag.doTag(); assertThat(response.getContentAsString(), is("")); }
Example 12
Source File: JseInformationsTagTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
@Test public void インフォメーションメッセージがフラッシュスコープにセットされ出力される() throws Exception { MessageContext context = new MessageContext(request); context.saveInformationMessageToFlash("I-JX_INFORMATIONS_TAG_TEST#0001"); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); request.setAttribute(MessageContext.INFORMATION_MESSAGE_KEY_TO_FLASH, flashMap.get(MessageContext.INFORMATION_MESSAGE_KEY_TO_FLASH)); JseInformationsTag tag = new JseInformationsTag(); tag.setJspContext(page); tag.doTag(); assertThat(response.getContentAsString(), is("<div class=\"jfw_messages\">" + "<p class=\"jfw_msg_style\">I-JX_INFORMATIONS_TAG_TEST#0001</p></div>")); }
Example 13
Source File: MessageContextTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
private List<String> getMessageFromFlash(String key) { FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); Messages messages = (Messages) flashMap.get(key); if (messages != null && !messages.isEmpty()) return messages.getMessageList(); return null; }
Example 14
Source File: JseErrorsTagTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
@Test public void エラーメッセージがフラッシュスコープにセットされ出力される() throws Exception { MessageContext context = new MessageContext(request); context.saveErrorMessageToFlash("E-JX_ERRORS_TAG_TEST#0001"); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); request.setAttribute(MessageContext.ERROR_MESSAGE_KEY_TO_FLASH, flashMap.get(MessageContext.ERROR_MESSAGE_KEY_TO_FLASH)); JseErrorsTag tag = new JseErrorsTag(); tag.setJspContext(page); tag.doTag(); assertThat(response.getContentAsString(), is("<div class=\"jfw_messages\">" + "<p class=\"jfw_err_msg_style\">E-JX_ERRORS_TAG_TEST#0001</p></div>")); }
Example 15
Source File: PageRestController.java From wallride with Apache License 2.0 | 5 votes |
@RequestMapping(value="/{language}/pages/{id}", method= RequestMethod.DELETE) public @ResponseBody DomainObjectDeletedModel<Long> delete( @PathVariable String language, @PathVariable long id, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { Page page = pageService.deletePage(id, language); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("deletedPage", page); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectDeletedModel<>(page); }
Example 16
Source File: CategoryRestController.java From wallride with Apache License 2.0 | 5 votes |
@RequestMapping(value="/{language}/categories/{id}", method= RequestMethod.DELETE) public @ResponseBody DomainObjectDeletedModel<Long> delete( @PathVariable String language, @PathVariable long id, AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) throws BindException { Category category = categoryService.deleteCategory(id, language); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put("deletedCategory", category); RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response); return new DomainObjectDeletedModel<>(category); }
Example 17
Source File: HtmlExceptionHandler.java From spring-boot-doma2-sample with Apache License 2.0 | 5 votes |
/** * FlashMapに値を書き出します。 * * @param request * @param response * @param attr * @param value */ protected void outputFlashMap(HttpServletRequest request, HttpServletResponse response, String attr, String value) { val flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put(attr, value); // flashMapを書き込む val flashManager = RequestContextUtils.getFlashMapManager(request); flashManager.saveOutputFlashMap(flashMap, request, response); }
Example 18
Source File: DefaultMvcResult.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public FlashMap getFlashMap() { return RequestContextUtils.getOutputFlashMap(mockRequest); }
Example 19
Source File: DefaultMvcResult.java From java-technology-stack with MIT License | 4 votes |
@Override public FlashMap getFlashMap() { return RequestContextUtils.getOutputFlashMap(this.mockRequest); }
Example 20
Source File: PostBackManager.java From sinavi-jfw with Apache License 2.0 | 2 votes |
/** * {@link PostBack}インスタンスをフラッシュ・スコープに保存します。 * @param request {@link HttpServletRequest} インスタンス * @param postBack {@link PostBack}インスタンス */ public static void saveToFlash(HttpServletRequest request, PostBack postBack) { FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); flashMap.put(PostBack.POST_BACK_ATTRIBUTE_KEY, postBack); }