View Javadoc

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