View Javadoc

1   /*
2    * $Id: DirectRenderFromEventAction.java 568895 2007-08-23 08:57:36Z rgielen $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.portlet.dispatcher;
22  
23  import com.opensymphony.xwork2.Action;
24  
25  import java.io.Serializable;
26  import java.util.Map;
27  
28  import org.apache.struts2.interceptor.SessionAware;
29  import org.apache.struts2.portlet.PortletActionConstants;
30  
31  /***
32   * When a portlet is targetted for an <code>event</code>, the portlet will receive two
33   * portlet requests, one for the <code>event</code> phase, and then followed by a <code>render</code>
34   * operation. When in the <code>event</code> phase, the action that is executed can't render
35   * any output. This means that if an action in the XWork configuration is executed in the event
36   * phase, and the action is set up with a result that should render something, the result can't
37   * immediately be executed. The portlet needs to "wait" to the render phase to do the
38   * rendering.
39   * <p/>
40   * When the {@link org.apache.struts2.portlet.result.PortletResult} detects such a
41   * scenario, instead of executing the actual view, it prepares a couple of render parameters
42   * specifying this action and the location of the view, which then will be executed in the
43   * following render request.
44   */
45  public class DirectRenderFromEventAction implements SessionAware, PortletActionConstants, Action, Serializable {
46  
47      private static final long serialVersionUID = -1814807772308405785L;
48  
49      private String location = null;
50  
51      /***
52       * Get the location of the view.
53       *
54       * @return Returns the location.
55       */
56      public String getLocation() {
57          return location;
58      }
59  
60      /***
61       * Always return success.
62       *
63       * @return SUCCESS
64       */
65      public String execute() throws Exception {
66          return SUCCESS;
67      }
68  
69      public void setSession(Map session) {
70          location = (String)session.get(RENDER_DIRECT_LOCATION);
71      }
72  }