Search in sources :

Example 1 with AbstractGrailsView

use of org.grails.web.servlet.view.AbstractGrailsView in project grails-core by grails.

the class SpringMVCViewDecorator method render.

public void render(Content content, Map<String, ?> model, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext) {
    HTMLPage htmlPage = GSPSitemeshPage.content2htmlPage(content);
    request.setAttribute(RequestConstants.PAGE, htmlPage);
    // get the dispatcher for the decorator
    if (!response.isCommitted()) {
        boolean dispatched = false;
        try {
            request.setAttribute(GrailsLayoutView.GSP_SITEMESH_PAGE, new GSPSitemeshPage(true));
            try {
                view.render(model, request, response);
                dispatched = true;
                if (!response.isCommitted()) {
                    response.getWriter().flush();
                }
            } catch (Exception e) {
                cleanRequestAttributes(request);
                String message = "Error applying layout : " + getName();
                if (view instanceof AbstractGrailsView) {
                    ((AbstractGrailsView) view).rethrowRenderException(e, message);
                } else {
                    throw new RuntimeException(message, e);
                }
            }
        } finally {
            if (!dispatched) {
                cleanRequestAttributes(request);
            }
        }
    }
    request.removeAttribute(RequestConstants.PAGE);
    request.removeAttribute(GrailsLayoutView.GSP_SITEMESH_PAGE);
}
Also used : HTMLPage(com.opensymphony.module.sitemesh.HTMLPage) AbstractGrailsView(org.grails.web.servlet.view.AbstractGrailsView)

Example 2 with AbstractGrailsView

use of org.grails.web.servlet.view.AbstractGrailsView in project grails-core by grails.

the class GroovyPageLayoutFinder method getNamedDecorator.

public Decorator getNamedDecorator(HttpServletRequest request, String name, boolean viewMustExist) {
    if (GrailsStringUtils.isBlank(name) || NONE_LAYOUT.equals(name)) {
        return null;
    }
    if (cacheEnabled) {
        DecoratorCacheValue cacheValue = decoratorCache.get(name);
        if (cacheValue != null && (!gspReloadEnabled || !cacheValue.isExpired())) {
            return cacheValue.getDecorator();
        }
    }
    View view;
    try {
        view = viewResolver.resolveViewName(GrailsResourceUtils.cleanPath(GrailsResourceUtils.appendPiecesForUri(LAYOUTS_PATH, name)), request.getLocale());
        // it's only possible to check that GroovyPageView exists
        if (viewMustExist && !(view instanceof AbstractGrailsView)) {
            view = null;
        }
    } catch (Exception e) {
        throw new RuntimeException("Unable to resolve view", e);
    }
    Decorator d = null;
    if (view != null) {
        d = createDecorator(name, view);
    }
    if (cacheEnabled) {
        decoratorCache.put(name, new DecoratorCacheValue(d));
    }
    return d;
}
Also used : Decorator(com.opensymphony.module.sitemesh.Decorator) AbstractGrailsView(org.grails.web.servlet.view.AbstractGrailsView) AbstractGrailsView(org.grails.web.servlet.view.AbstractGrailsView) View(org.springframework.web.servlet.View)

Aggregations

AbstractGrailsView (org.grails.web.servlet.view.AbstractGrailsView)2 Decorator (com.opensymphony.module.sitemesh.Decorator)1 HTMLPage (com.opensymphony.module.sitemesh.HTMLPage)1 View (org.springframework.web.servlet.View)1