View Javadoc

1   /*
2    * $Id: FacesRender.java 651946 2008-04-27 13:41:38Z apetrelli $
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  
22  package org.apache.struts2.jsf;
23  
24  import java.io.IOException;
25  
26  import javax.faces.FacesException;
27  import javax.faces.application.Application;
28  import javax.faces.application.ViewHandler;
29  import javax.faces.context.FacesContext;
30  import javax.faces.event.PhaseId;
31  
32  /***
33   * Performs the JSF render lifecycle phase.
34   *
35   */
36  public class FacesRender extends FacesSupport {
37  
38      /***
39       * Executes the render phase, borrowed from MyFaces
40       *
41       * @param facesContext
42       *            The faces context
43       * @throws FacesException
44       *             If anything goes wrong
45       */
46      public void render(FacesContext facesContext) throws FacesException {
47          // if the response is complete we should not be invoking the phase
48          // listeners
49          if (isResponseComplete(facesContext, "render", true)) {
50              return;
51          }
52          if (log.isTraceEnabled())
53              log.trace("entering renderResponse");
54  
55          informPhaseListenersBefore(facesContext, PhaseId.RENDER_RESPONSE);
56          try {
57              // also possible that one of the listeners completed the response
58              if (isResponseComplete(facesContext, "render", true)) {
59                  return;
60              }
61              Application application = facesContext.getApplication();
62              ViewHandler viewHandler = application.getViewHandler();
63              try {
64                  viewHandler
65                          .renderView(facesContext, facesContext.getViewRoot());
66              } catch (IOException e) {
67                  throw new FacesException(e.getMessage(), e);
68              }
69          } finally {
70              informPhaseListenersAfter(facesContext, PhaseId.RENDER_RESPONSE);
71          }
72          if (log.isTraceEnabled()) {
73              // Note: DebugUtils Logger must also be in trace level
74              // DebugUtils.traceView("View after rendering");
75          }
76  
77          if (log.isTraceEnabled())
78              log.trace("exiting renderResponse");
79      }
80  }