KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > tiles > test > NoForward


1 /*
2  * $Id: NoForward.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.struts.webapp.tiles.test;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23
24 import org.apache.struts.action.Action;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.tiles.ComponentContext;
29
30
31 /**
32  * Implementation of <strong>Action</strong> that create a TileContext in order
33  * to force the TilesRequestProcessor to do an include instead of a forward.
34  * The side effect is that request.getRequestURI will return the URL of the
35  * calling struts action instead of the URL of the tiles layout.
36  * See the jsp documentation to understand why.
37  * Usage:
38  * use this action in conjunction with an action declaration in struts config.
39  * The action declaration should have one "success" forward to a Tile.
40  * <pre>
41  * <action path="/showRequestURI"
42  * type="org.apache.struts.webapp.tiles.test.NoForward">
43  * <forward name="success" path="test.action.noforward"/>
44  * </action>
45  * </pre>
46  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
47  */

48
49 public final class NoForward extends Action {
50
51
52
53     // --------------------------------------------------------- Public Methods
54

55
56     /**
57      *
58      * @param mapping The ActionMapping used to select this instance
59      * @param form The optional ActionForm bean for this request (if any)
60      * @param request The HTTP request we are processing
61      * @param response The HTTP response we are creating
62      *
63      * @exception Exception if the application business logic throws
64      * an exception
65      * @since Struts 1.1
66      */

67     public ActionForward execute(ActionMapping mapping,
68                                  ActionForm form,
69                                  HttpServletRequest JavaDoc request,
70                                  HttpServletResponse JavaDoc response)
71         throws Exception JavaDoc {
72       // Try to retrieve tile context
73
ComponentContext context = ComponentContext.getContext( request );
74     if( context == null )
75       { // Not found, create a context
76
// This context will be detected by the TilesRequestProcessor which will do an include
77
// instead of a forward.
78
ComponentContext tileContext = new ComponentContext( );
79       ComponentContext.setContext( tileContext, request);
80       }
81       return (mapping.findForward("success"));
82     }
83
84
85 }
86
Popular Tags