All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.struts2.views.tiles.TilesResult Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
/*
 * $Id: TilesResult.java 651946 2008-04-27 13:41:38Z apetrelli $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.struts2.views.tiles;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import org.apache.tiles.TilesContainer;
import org.apache.tiles.access.TilesAccess;

import com.opensymphony.xwork2.ActionInvocation;

/**
 * 
 * Renders a view using struts-tiles.
 * 
 *
 * 
 * In your web.xml file, you need to add a servlet entry for TilesServlet to load the tiles
 * definitions into the ServletContext.
 *
 * <servlet>
 *      <servlet-name>tiles</servlet-name>
 *      <servlet-class>org.apache.tiles.servlets.TilesServlet</servlet-class>
 *      <init-param>
 *          <param-name>definitions-config</param-name>
 *          <param-value>/WEB-INF/tiles-config.xml</param-value>
 *      </init-param>
 *      <load-on-startup>1</load-on-startup>
 * </servlet>
 * 
 *
 * 
 * In struts.xml, use type="tiles" on your <result>.
 *
 * <action name="editUser" class="userAction" method="edit">
 *      <result name="success" type="tiles">userForm</result>
 *      <result name="input" type="tiles">userList</result>
 * </action>
 * 
 *
 *
 * 
 *
 * Making this result type the default for the current package.
 *
 * <result-types>
 *      <result-type name="tiles"
 * class="org.apache.struts2.views.tiles.TilesResult" default="true" />
 * </result-types>
 * 
 *
 */
public class TilesResult extends ServletDispatcherResult {

    private static final long serialVersionUID = -3806939435493086244L;

    public TilesResult() {
        super();
    }

    public TilesResult(String location) {
        super(location);
    }
    /**
     * 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 {
        setLocation(location);

        ServletContext servletContext = ServletActionContext.getServletContext();
        TilesContainer container = TilesAccess.getContainer(servletContext);

        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();

        container.render(location, request, response);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy