Search in sources :

Example 1 with TilesContainer

use of org.apache.tiles.TilesContainer in project spring-framework by spring-projects.

the class TilesView method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    this.applicationContext = ServletUtil.getApplicationContext(getServletContext());
    if (this.renderer == null) {
        TilesContainer container = TilesAccess.getContainer(this.applicationContext);
        this.renderer = new DefinitionRenderer(container);
    }
}
Also used : DefinitionRenderer(org.apache.tiles.renderer.DefinitionRenderer) TilesContainer(org.apache.tiles.TilesContainer)

Example 2 with TilesContainer

use of org.apache.tiles.TilesContainer in project spring-framework-debug by Joker-5.

the class TilesView method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    ServletContext servletContext = getServletContext();
    Assert.state(servletContext != null, "No ServletContext");
    this.applicationContext = ServletUtil.getApplicationContext(servletContext);
    if (this.renderer == null) {
        TilesContainer container = TilesAccess.getContainer(this.applicationContext);
        this.renderer = new DefinitionRenderer(container);
    }
}
Also used : DefinitionRenderer(org.apache.tiles.renderer.DefinitionRenderer) ServletContext(javax.servlet.ServletContext) TilesContainer(org.apache.tiles.TilesContainer)

Example 3 with TilesContainer

use of org.apache.tiles.TilesContainer in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class TilesView method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    ServletContext servletContext = getServletContext();
    Assert.state(servletContext != null, "No ServletContext");
    this.applicationContext = ServletUtil.getApplicationContext(servletContext);
    if (this.renderer == null) {
        TilesContainer container = TilesAccess.getContainer(this.applicationContext);
        this.renderer = new DefinitionRenderer(container);
    }
}
Also used : DefinitionRenderer(org.apache.tiles.renderer.DefinitionRenderer) ServletContext(javax.servlet.ServletContext) TilesContainer(org.apache.tiles.TilesContainer)

Example 4 with TilesContainer

use of org.apache.tiles.TilesContainer in project struts by apache.

the class TilesResult method doExecute.

/**
 * Dispatches to the given location. Does its forward via a RequestDispatcher. If the
 * dispatch fails a 404 error will be sent back in the http response.
 *
 * @param location the location to dispatch to.
 * @param invocation    the execution state of the action
 * @throws Exception if an error occurs. If the dispatch fails the error will go back via the
 *                   HTTP request.
 */
public void doExecute(String location, ActionInvocation invocation) throws Exception {
    StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor();
    TilesDefinition tilesDefinition = null;
    Object action = invocation.getAction();
    String actionName = invocation.getInvocationContext().getName();
    if (StringUtils.isEmpty(location)) {
        LOG.trace("location not set -> action must have one @TilesDefinition");
        tilesDefinition = annotationProcessor.findAnnotation(action, null);
        String tileName = StringUtils.isNotEmpty(tilesDefinition.name()) ? tilesDefinition.name() : actionName;
        location = tileName;
        LOG.debug("using new location name '{}' and @TilesDefinition '{}'", location, tilesDefinition);
    }
    setLocation(location);
    ServletContext servletContext = ServletActionContext.getServletContext();
    ApplicationContext applicationContext = ServletUtil.getApplicationContext(servletContext);
    TilesContainer container = TilesAccess.getContainer(applicationContext);
    HttpServletRequest httpRequest = ServletActionContext.getRequest();
    HttpServletResponse httpResponse = ServletActionContext.getResponse();
    Request request = new ServletRequest(applicationContext, httpRequest, httpResponse);
    boolean definitionValid = false;
    try {
        LOG.debug("checking if tiles definition exists '{}'", location);
        definitionValid = container.isValidDefinition(location, request);
    } catch (TilesException e) {
        LOG.warn("got TilesException while checking if definiton exists, ignoring it", e);
    }
    if (!definitionValid) {
        if (tilesDefinition == null) {
            LOG.trace("tilesDefinition not found yet, searching in action");
            tilesDefinition = annotationProcessor.findAnnotation(action, location);
        }
        if (tilesDefinition != null) {
            Definition definition = annotationProcessor.buildTilesDefinition(location, tilesDefinition);
            if (container instanceof MutableTilesContainer) {
                LOG.debug("registering tiles definition with name '{}'", definition.getName());
                ((MutableTilesContainer) container).register(definition, request);
            } else {
                LOG.error("cannot register tiles definition as tiles container is not mutable!");
            }
        } else {
            LOG.warn("could not find @TilesDefinition for action: {}", actionName);
        }
    }
    container.render(location, request);
}
Also used : ServletRequest(org.apache.tiles.request.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) TilesException(org.apache.tiles.TilesException) ServletRequest(org.apache.tiles.request.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.tiles.request.Request) Definition(org.apache.tiles.Definition) TilesDefinition(org.apache.struts2.tiles.annotation.TilesDefinition) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) TilesDefinition(org.apache.struts2.tiles.annotation.TilesDefinition) ApplicationContext(org.apache.tiles.request.ApplicationContext) MutableTilesContainer(org.apache.tiles.mgmt.MutableTilesContainer) StrutsTilesAnnotationProcessor(org.apache.struts2.tiles.StrutsTilesAnnotationProcessor) ServletContext(javax.servlet.ServletContext) TilesContainer(org.apache.tiles.TilesContainer) MutableTilesContainer(org.apache.tiles.mgmt.MutableTilesContainer)

Example 5 with TilesContainer

use of org.apache.tiles.TilesContainer in project struts by apache.

the class PortletTilesResult method executeRenderResult.

protected void executeRenderResult(String location) throws TilesException {
    setLocation(location);
    PortletContext portletContext = PortletActionContext.getPortletContext();
    RenderRequest request = PortletActionContext.getRenderRequest();
    RenderResponse response = PortletActionContext.getRenderResponse();
    TilesContainer container = getCurrentContainer(request, portletContext);
    ApplicationContext applicationContext = container.getApplicationContext();
    Request currentRequest = new RenderPortletRequest(applicationContext, portletContext, request, response);
    container.render(location, currentRequest);
}
Also used : ApplicationContext(org.apache.tiles.request.ApplicationContext) RenderRequest(javax.portlet.RenderRequest) RenderPortletRequest(org.apache.tiles.request.portlet.RenderPortletRequest) Request(org.apache.tiles.request.Request) RenderRequest(javax.portlet.RenderRequest) PortletContext(javax.portlet.PortletContext) RenderPortletRequest(org.apache.tiles.request.portlet.RenderPortletRequest) RenderResponse(javax.portlet.RenderResponse) TilesContainer(org.apache.tiles.TilesContainer)

Aggregations

TilesContainer (org.apache.tiles.TilesContainer)7 ServletContext (javax.servlet.ServletContext)4 DefinitionRenderer (org.apache.tiles.renderer.DefinitionRenderer)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ApplicationContext (org.apache.tiles.request.ApplicationContext)2 Request (org.apache.tiles.request.Request)2 ServletRequest (org.apache.tiles.request.servlet.ServletRequest)2 PortletContext (javax.portlet.PortletContext)1 RenderRequest (javax.portlet.RenderRequest)1 RenderResponse (javax.portlet.RenderResponse)1 StrutsTilesAnnotationProcessor (org.apache.struts2.tiles.StrutsTilesAnnotationProcessor)1 TilesDefinition (org.apache.struts2.tiles.annotation.TilesDefinition)1 TilesResult (org.apache.struts2.views.tiles.TilesResult)1 Definition (org.apache.tiles.Definition)1 TilesException (org.apache.tiles.TilesException)1 MutableTilesContainer (org.apache.tiles.mgmt.MutableTilesContainer)1 RenderPortletRequest (org.apache.tiles.request.portlet.RenderPortletRequest)1 ServletApplicationContext (org.apache.tiles.request.servlet.ServletApplicationContext)1