Example usage for org.springframework.web.servlet.support RequestContext RequestContext

List of usage examples for org.springframework.web.servlet.support RequestContext RequestContext

Introduction

In this page you can find the example usage for org.springframework.web.servlet.support RequestContext RequestContext.

Prototype

public RequestContext(HttpServletRequest request, @Nullable Map<String, Object> model) 

Source Link

Document

Create a new RequestContext for the given request, using the given model attributes for Errors retrieval.

Usage

From source file:com.spt.evt.view.PartialRenderingTilesView.java

protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    ServletContext servletContext = getServletContext();
    if ("nolayout".equals(request.getParameter("htmlFormat"))) {

        BasicTilesContainer container = (BasicTilesContainer) ServletUtil.getCurrentContainer(request,
                servletContext);//w w w  .ja  v  a 2 s  .  c o  m
        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));

        TilesRequestContext tilesRequestContext = tilesRequestContextFactory
                .createRequestContext(container.getApplicationContext(), new Object[] { request, response });
        Definition compositeDefinition = container.getDefinitionsFactory().getDefinition(getUrl(),
                tilesRequestContext);

        Iterator<String> iterator = compositeDefinition.getAttributeNames();
        while (iterator.hasNext()) {
            String attributeName = (String) iterator.next();
            Attribute attribute = compositeDefinition.getAttribute(attributeName);
            if (attribute.getValue() == null || !(attribute.getValue() instanceof String)) {
                continue;
            }
            container.startContext(request, response).inheritCascadedAttributes(compositeDefinition);
            container.render(attribute, request, response);
            container.endContext(request, response);
        }
    } else {
        super.renderMergedOutputModel(model, request, response);
    }
}

From source file:com.parakhcomputer.web.servlet.view.tiles2.DynamicTilesViewProcessor.java

/**
 * Renders output using Tiles.//from  w w w  .  j av  a  2 s .c o m
 */
protected void renderMergedOutputModel(String beanName, String url, ServletContext servletContext,
        HttpServletRequest request, HttpServletResponse response, TilesContainer container) throws Exception {
    JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext));

    if (!response.isCommitted()) {
        // Tiles is going to use a forward, but some web containers (e.g.
        // OC4J 10.1.3)
        // do not properly expose the Servlet 2.4 forward request
        // attributes... However,
        // must not do this on Servlet 2.5 or above, mainly for GlassFish
        // compatibility.
        if (servletContext.getMajorVersion() == 2 && servletContext.getMinorVersion() < 5) {
            WebUtils.exposeForwardRequestAttributes(request);
        }
    }

    String definitionName = startDynamicDefinition(beanName, url, request, response, container);

    container.render(definitionName, request, response);

    endDynamicDefinition(definitionName, beanName, request, response, container);
}

From source file:net.vksn.ecm.spring.tiles3.TilesView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    exposeModelAsRequestAttributes(model, request);

    if (this.exposeJstlAttributes) {
        ServletContext servletContext = getServletContext();
        JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext));
    }//from   w w w. j  ava  2  s  .c o m

    if (!response.isCommitted()) {
        // Tiles is going to use a forward, but some web containers (e.g.
        // OC4J 10.1.3)
        // do not properly expose the Servlet 2.4 forward request
        // attributes... However,
        // must not do this on Servlet 2.5 or above, mainly for GlassFish
        // compatibility.
        if (this.exposeForwardAttributes) {
            try {
                WebUtils.exposeForwardRequestAttributes(request);
            } catch (Exception ex) {
                // Servlet container rejected to set internal attributes,
                // e.g. on TriFork.
                this.exposeForwardAttributes = false;
            }
        }
    }

    Request tilesRequest = createTilesRequest(request, response);
    this.renderer.render(getUrl(), tilesRequest);
}

From source file:org.hdiv.web.servlet.tags.form.AbstractHtmlElementTagTests.java

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);
}

From source file:ua.com.manometer.jasperreports.AbstractJasperReportsView.java

/**
 * 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</code> method.
 * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
 * @see org.springframework.context.support.MessageSourceResourceBundle
 * @see #getApplicationContext()/*from  w w w.  ja v a 2 s .co m*/
 * @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());
    if (!model.containsKey(JRParameter.REPORT_LOCALE)) {
        model.put(JRParameter.REPORT_LOCALE, rc.getLocale());
    }
    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(), rc.getLocale()));
    }
}