Java Code Examples for org.springframework.web.servlet.support.RequestContext

The following examples show how to use org.springframework.web.servlet.support.RequestContext. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: TilesView.java    License: MIT License 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

	Assert.state(this.renderer != null, "No Renderer set");

	exposeModelAsRequestAttributes(model, request);
	if (this.exposeJstlAttributes) {
		JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext()));
	}
	if (this.alwaysInclude) {
		request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
	}

	Request tilesRequest = createTilesRequest(request, response);
	this.renderer.render(getUrl(), tilesRequest);
}
 
Example 2
Source Project: BlogSystem   Source File: EmailController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 发送反馈邮件
 */
@RequestMapping(value = "/feedback", method = RequestMethod.POST)
public ResultBean sendFeedback(HttpServletRequest request,
                               @RequestParam(value = "bloggerId", required = false) Integer bloggerId,
                               @RequestParam("content") String content,
                               @RequestParam(value = "contact", required = false) String contact) {
    if (bloggerId != null) {
        handleBloggerSignInCheck(request, bloggerId);
    }

    String subject = new RequestContext(request).getMessage("common.feedbackTitle");
    if (!emailService.sendFeedback(bloggerId == null ? -1 : bloggerId, subject, content, contact))
        handlerOperateFail(request);

    return new ResultBean<>("");
}
 
Example 3
Source Project: spring-analysis-note   Source File: MessageTagTests.java    License: MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
Example 4
Source Project: spring-analysis-note   Source File: ThemeTagTests.java    License: MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
	assertEquals("theme test message", rc.getThemeMessage("themetest"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
	assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
	assertEquals("default", rc.getThemeMessage("themetesta", "default"));
	assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
	assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
 
Example 5
Source Project: java-technology-stack   Source File: TilesView.java    License: MIT License 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

	Assert.state(this.renderer != null, "No Renderer set");

	exposeModelAsRequestAttributes(model, request);
	if (this.exposeJstlAttributes) {
		JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext()));
	}
	if (this.alwaysInclude) {
		request.setAttribute(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
	}

	Request tilesRequest = createTilesRequest(request, response);
	this.renderer.render(getUrl(), tilesRequest);
}
 
Example 6
Source Project: spring4-understanding   Source File: ThemeTagTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
	assertEquals("theme test message", rc.getThemeMessage("themetest"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (String[]) null));
	assertEquals("theme test message", rc.getThemeMessage("themetest", "default"));
	assertEquals("theme test message", rc.getThemeMessage("themetest", (Object[]) null, "default"));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", new String[] {"arg1"}));
	assertEquals("theme test message arg1",
			rc.getThemeMessage("themetestArgs", Arrays.asList(new String[] {"arg1"})));
	assertEquals("default", rc.getThemeMessage("themetesta", "default"));
	assertEquals("default", rc.getThemeMessage("themetesta", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
	assertEquals("theme test message", rc.getThemeMessage(resolvable));
}
 
Example 7
/**
 * Expose current Spring-managed Locale and MessageSource to JasperReports i18n
 * ($R expressions etc). The MessageSource should only be exposed as JasperReports
 * resource bundle if no such bundle is defined in the report itself.
 * <p>The default implementation exposes the Spring RequestContext Locale and a
 * MessageSourceResourceBundle adapter for the Spring ApplicationContext,
 * analogous to the {@code JstlUtils.exposeLocalizationContext} method.
 * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
 * @see org.springframework.context.support.MessageSourceResourceBundle
 * @see #getApplicationContext()
 * @see net.sf.jasperreports.engine.JRParameter#REPORT_LOCALE
 * @see net.sf.jasperreports.engine.JRParameter#REPORT_RESOURCE_BUNDLE
 * @see org.springframework.web.servlet.support.JstlUtils#exposeLocalizationContext
 */
protected void exposeLocalizationContext(Map<String, Object> model, HttpServletRequest request) {
	RequestContext rc = new RequestContext(request, getServletContext());
	Locale locale = rc.getLocale();
	if (!model.containsKey(JRParameter.REPORT_LOCALE)) {
		model.put(JRParameter.REPORT_LOCALE, locale);
	}
	TimeZone timeZone = rc.getTimeZone();
	if (timeZone != null && !model.containsKey(JRParameter.REPORT_TIME_ZONE)) {
		model.put(JRParameter.REPORT_TIME_ZONE, timeZone);
	}
	JasperReport report = getReport();
	if ((report == null || report.getResourceBundle() == null) &&
			!model.containsKey(JRParameter.REPORT_RESOURCE_BUNDLE)) {
		model.put(JRParameter.REPORT_RESOURCE_BUNDLE,
				new MessageSourceResourceBundle(rc.getMessageSource(), locale));
	}
}
 
Example 8
Source Project: BlogSystem   Source File: ImageController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 输出公开图片,这些图片无需验证登录,如果数据库不存在指定图片,则返回默认图片
 */
@RequestMapping(value = "/type=public/{imageId}", method = RequestMethod.GET)
public void getBlogPicture(HttpServletRequest request, HttpServletResponse response,
                           @PathVariable("bloggerId") Integer bloggerId,
                           @PathVariable("imageId") Integer imageId,
                           @RequestParam(value = "default", required = false) Integer category) {
    handleAccountCheck(request, bloggerId);

    // 检查default是否为默认类别
    if (category != null)
        handleBlogCategoryDefaultCheck(request, category);

    BloggerPicture picture = bloggerPictureService.getPicture(imageId, bloggerId);

    // 如果图片是私有的,不能访问
    if (picture != null && picture.getCategory().equals(BloggerPictureCategoryEnum.PRIVATE.getCode()))
        throw exceptionManager.getUnauthorizedException(new RequestContext(request));

    BloggerPicture backupPicture = bloggerPictureService.getDefaultPicture(
            category == null ? BloggerPictureCategoryEnum.DEFAULT_PICTURE
                    : BloggerPictureCategoryEnum.valueOf(category)); //如果目标图片不存在,返回指定类别的默认图片

    // 输出图片
    outPutPicture(picture, backupPicture, request, response);

}
 
Example 9
Source Project: java-technology-stack   Source File: MessageTagTests.java    License: MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
Example 10
Source Project: BlogSystem   Source File: BloggerGalleryController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 从设备和数据库中删除图片
 */
@RequestMapping(value = "/{pictureId}", method = RequestMethod.DELETE)
@ResponseBody
public ResultBean delete(HttpServletRequest request,
                         @PathVariable("bloggerId") Integer bloggerId,
                         @PathVariable("pictureId") Integer pictureId) {
    handleBloggerSignInCheck(request, bloggerId);

    BloggerPicture picture = bloggerPictureService.getPicture(pictureId, bloggerId);
    if (picture == null) {
        throw exceptionManager.getUnknownPictureException(new RequestContext(request));
    }

    //检查权限
    if (!validateManager.checkBloggerPictureLegal(bloggerId, picture.getCategory()))
        throw exceptionManager.getUnauthorizedException(new RequestContext(request));

    boolean succ = bloggerPictureService.deletePicture(bloggerId, picture.getId(), true);
    if (!succ) handlerOperateFail(request);

    return new ResultBean<>("");
}
 
Example 11
Source Project: lams   Source File: TilesView.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void renderMergedOutputModel(
		Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {

	ServletContext servletContext = getServletContext();
	TilesContainer container = ServletUtil.getContainer(servletContext);
	if (container == null) {
		throw new ServletException("Tiles container is not initialized. " +
				"Have you added a TilesConfigurer to your web application context?");
	}

	exposeModelAsRequestAttributes(model, request);
	JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext));
	if (this.alwaysInclude) {
		ServletUtil.setForceInclude(request, true);
	}
	container.render(getUrl(), request, response);
}
 
Example 12
Source Project: BlogSystem   Source File: BloggerBlogController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 下载博文
 */
@RequestMapping(value = "/download-type={type}", method = RequestMethod.GET)
public void download(HttpServletRequest request, HttpServletResponse response,
                     @PathVariable Integer bloggerId,
                     @PathVariable String type) {
    handleBloggerSignInCheck(request, bloggerId);

    // 检查请求的文件类别
    BlogFormatEnum format = BlogFormatEnum.get(type);
    if (format == null) {
        throw exceptionManager.getParameterIllegalException(new RequestContext(request));
    }

    String zipFilePath = bloggerBlogService.getAllBlogForDownload(bloggerId, format);
    if (StringUtils.isEmpty(zipFilePath)) handlerOperateFail(request);

    // 输出文件流
    outFile(zipFilePath, request, response);

    // 删除临时 zip 文件
    fileManager.deleteFileIfExist(zipFilePath);
}
 
Example 13
Source Project: BlogSystem   Source File: BloggerCollectBlogController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 修改博文收藏
 */
@RequestMapping(value = "/{blogId}", method = RequestMethod.PUT)
public ResultBean update(HttpServletRequest request,
                         @PathVariable("blogId") Integer blogId,
                         @PathVariable("bloggerId") Integer bloggerId,
                         @RequestParam(value = "reason", required = false) String newReason) {

    handleBloggerSignInCheck(request, bloggerId);

    if (StringUtils.isEmpty(newReason)) {
        throw exceptionManager.getParameterIllegalException(new RequestContext(request));
    }

    boolean result = bloggerCollectBlogService.updateCollect(bloggerId, blogId, newReason, -1);
    if (!result) handlerOperateFail(request);

    return new ResultBean<>("");
}
 
Example 14
Source Project: BlogSystem   Source File: BloggerOperateController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 投诉博文
 */
@RequestMapping(value = "/operate=complain", method = RequestMethod.POST)
public ResultBean complainBlog(HttpServletRequest request,
                               @PathVariable Integer blogId,
                               @PathVariable Integer bloggerId,
                               @RequestParam("content") String content) {
    if (StringUtils.isEmpty_(content))
        throw exceptionManager.getParameterIllegalException(new RequestContext(request));

    handleBloggerSignInCheck(request, bloggerId);
    handleBlogExistCheck(request, blogId);

    //执行
    int id = operateService.insertComplain(blogId, bloggerId, content);
    if (id <= 0) handlerOperateFail(request);

    return new ResultBean<>(id);
}
 
Example 15
Source Project: BlogSystem   Source File: BloggerCommentController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 新增评论
 */
@RequestMapping(method = RequestMethod.POST)
public ResultBean add(HttpServletRequest request,
                      @PathVariable Integer bloggerId,
                      @RequestParam("blogId") Integer blogId,
                      @RequestParam("content") String content,
                      @RequestParam("listenerId") Integer listenerId) {
    handleBloggerSignInCheck(request, bloggerId);
    handleBlogExistCheck(request, blogId);
    handleBloggerExist(request, listenerId);

    if (StringUtils.isEmpty_(content) || !commentValidateManager.checkCommentContent(content))
        throw exceptionManager.getParameterIllegalException(new RequestContext(request));

    int id = commentService.insertComment(blogId, bloggerId, listenerId, RIGHTFUL.getCode(), content);
    if (id < 0) handlerOperateFail(request);

    return new ResultBean<>(id);
}
 
Example 16
@Override
public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) {
    final RequestContext requestContext = new RequestContext(request, response, servletContext, (Map<String, Object>) model);

    if (requestContext.getContextPath() != null) {
        root.put(prefix + "contextPath", requestContext.getContextPath());
    }
    if (requestContext.getPathToServlet() != null) {
        root.put(prefix + "pathToServlet", requestContext.getPathToServlet());
    }
    if (requestContext.getQueryString() != null) {
        root.put(prefix + "queryString", requestContext.getQueryString());
    }
    if (requestContext.getRequestUri() != null) {
        root.put(prefix + "requestUri", requestContext.getRequestUri());
    }
    if (requestContext.getLocale() != null) {
        root.put(prefix + "locale", requestContext.getLocale().toString());
    }
}
 
Example 17
Source Project: spring-analysis-note   Source File: ViewResolverTests.java    License: MIT License 5 votes vote down vote up
private void doTestUrlBasedViewResolverWithoutPrefixes(UrlBasedViewResolver vr) throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());
	wac.refresh();
	vr.setApplicationContext(wac);
	vr.setContentType("myContentType");
	vr.setRequestContextAttribute("rc");

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((InternalResourceView) view).getUrl());
	assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType());

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((InternalResourceView) view).getUrl());
	assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType());

	HttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	Map<String, Object> model = new HashMap<>();
	TestBean tb = new TestBean();
	model.put("tb", tb);
	view.render(model, request, response);
	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct rc attribute", request.getAttribute("rc") instanceof RequestContext);

	view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
	assertEquals("Correct view class", RedirectView.class, view.getClass());
	assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());
	assertSame("View not initialized as bean", wac, ((RedirectView) view).getApplicationContext());

	view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
	assertEquals("Correct view class", InternalResourceView.class, view.getClass());
	assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
}
 
Example 18
Source Project: sinavi-jfw   Source File: PageNavigationTagTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {

    MockServletContext sc = new MockServletContext();
    WebApplicationContext wac = new StaticWebApplicationContext();
    sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    req = new MockHttpServletRequest(sc);
    resp = new MockHttpServletResponse();
    context = new MockPageContext(sc, req, resp);
    rcon = new RequestContext(req, sc);
    context.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, rcon);
}
 
Example 19
@Override
protected void renderMergedOutputModel(
		Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	RequestContext rc = new RequestContext(request, model);
	rc.getBindStatus("dataClass");
	rc.getBindStatus("dataClass.param1");
	rc.getBindStatus("dataClass.param2");
	rc.getBindStatus("dataClass.param3");
	response.getWriter().write(this.content);
}
 
Example 20
Source Project: es   Source File: SearchBindStatus.java    License: Apache License 2.0 5 votes vote down vote up
public static BindStatus create(PageContext pageContext, String name, RequestContext requestContext, boolean htmlEscape) {
    pageContext.getRequest().setAttribute(pathToUse, SearchModel.EMPTY);
    SearchBindStatus bindStatus = new SearchBindStatus(requestContext, pathToUse, htmlEscape);
    bindStatus.value = getValue(pageContext, name);
    bindStatus.htmlEscape = htmlEscape;
    return bindStatus;
}
 
Example 21
Source Project: spring-analysis-note   Source File: AbstractHtmlElementTagTests.java    License: MIT License 5 votes vote down vote up
protected MockPageContext createAndPopulatePageContext() throws JspException {
	MockPageContext pageContext = createPageContext();
	MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
	((StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request))
			.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	extendRequest(request);
	extendPageContext(pageContext);
	RequestContext requestContext = new JspAwareRequestContext(pageContext);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
	return pageContext;
}
 
Example 22
Source Project: ogham   Source File: SpringWebThymeleafContextConverter.java    License: Apache License 2.0 5 votes vote down vote up
protected static void addRequestContextAsVariable(final Map<String, Object> model, final String variableName, final RequestContext requestContext) throws ContextException {

		if (model.containsKey(variableName)) {
			throw new ContextException(new ServletException("Cannot expose request context in model attribute '" + variableName + "' because of an existing model object of the same name"));
		}
		model.put(variableName, requestContext);

	}
 
Example 23
Source Project: spring-analysis-note   Source File: AbstractHtmlElementTagTests.java    License: MIT License 5 votes vote down vote up
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map<String, Object> model = Collections.singletonMap(
			BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example 24
Source Project: spring-analysis-note   Source File: OptionsTagTests.java    License: MIT License 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example 25
Source Project: java-technology-stack   Source File: JstlView.java    License: MIT License 5 votes vote down vote up
/**
 * Exposes a JSTL LocalizationContext for Spring's locale and MessageSource.
 * @see JstlUtils#exposeLocalizationContext
 */
@Override
protected void exposeHelpers(HttpServletRequest request) throws Exception {
	if (this.messageSource != null) {
		JstlUtils.exposeLocalizationContext(request, this.messageSource);
	}
	else {
		JstlUtils.exposeLocalizationContext(new RequestContext(request, getServletContext()));
	}
}
 
Example 26
@Override
protected void renderMergedOutputModel(
		Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
	RequestContext rc = new RequestContext(request, model);
	rc.getBindStatus("dataClass");
	rc.getBindStatus("dataClass.param1");
	rc.getBindStatus("dataClass.param2");
	rc.getBindStatus("dataClass.param3");
	response.getWriter().write(this.content);
}
 
Example 27
Source Project: java-technology-stack   Source File: ErrorsTagTests.java    License: MIT License 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example 28
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map<String, Object> model = Collections.singletonMap(
			BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example 29
protected MockPageContext createAndPopulatePageContext() throws JspException {
	MockPageContext pageContext = createPageContext();
	MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
	StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request);
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	extendRequest(request);
	extendPageContext(pageContext);
	RequestContext requestContext = new JspAwareRequestContext(pageContext);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
	return pageContext;
}
 
Example 30
Source Project: ogham   Source File: SpringWebThymeleafContextConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public IContext convert(fr.sii.ogham.core.template.context.Context context) throws ContextException {
	IContext base = delegate.convert(context);
	
	// the web context may be lost due to @Async method call
	if (isAsyncCall()) {
		return base;
	}

	// partially borrowed from org.thymeleaf.spring5.view.ThymeleafView
	final Map<String, Object> springModel = new HashMap<>(30);

	HttpServletRequest request = webContextProvider.getRequest(context);
	HttpServletResponse response = webContextProvider.getResponse(context);
	ServletContext servletContext = webContextProvider.getServletContext(context);

	if (pathVariablesSelector != null) {
		@SuppressWarnings("unchecked")
		final Map<String, Object> pathVars = (Map<String, Object>) request.getAttribute(pathVariablesSelector);
		if (pathVars != null) {
			springModel.putAll(pathVars);
		}
	}

	final RequestContext requestContext = new RequestContext(request, response, servletContext, springModel);

	// For compatibility with ThymeleafView
	addRequestContextAsVariable(springModel, springRequestContextVariableName, requestContext);
	// For compatibility with AbstractTemplateView
	addRequestContextAsVariable(springModel, AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, requestContext);

	thymeleafRequestContextWrapper.wrapAndRegister(requestContext, request, response, servletContext, springModel);

	return contextMerger.merge(thymeleafWebContextProvider.getWebContext(context, base, request, response, servletContext, applicationContext, springModel), base);
}