Search in sources :

Example 1 with ServletApplicationContext

use of org.apache.tiles.request.servlet.ServletApplicationContext in project struts-examples by apache.

the class TilesUnknownHandler method handleUnknownResult.

public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig actionConfig, String resultCode) throws StrutsException {
    ServletContext servletContext = ServletActionContext.getServletContext();
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    ServletApplicationContext context = new ServletApplicationContext(servletContext);
    TilesContainer container = TilesAccess.getContainer(context);
    String namespace = ServletActionContext.getActionMapping().getNamespace();
    Set<String> definitions = buildDefinitionNames(namespace, actionName, resultCode);
    for (String definition : definitions) {
        LOG.debug("Looking for tiles definition: {}", definition);
        if (container.isValidDefinition(definition, new ServletRequest(context, request, response))) {
            return new TilesResult(definition);
        }
    }
    LOG.warn("Couldn't find tiles definition for namespace {}, action name {} and result code {}", namespace, actionName, resultCode);
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(org.apache.tiles.request.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletApplicationContext(org.apache.tiles.request.servlet.ServletApplicationContext) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) TilesResult(org.apache.struts2.views.tiles.TilesResult) TilesContainer(org.apache.tiles.TilesContainer)

Aggregations

ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 TilesResult (org.apache.struts2.views.tiles.TilesResult)1 TilesContainer (org.apache.tiles.TilesContainer)1 ServletApplicationContext (org.apache.tiles.request.servlet.ServletApplicationContext)1 ServletRequest (org.apache.tiles.request.servlet.ServletRequest)1