View Javadoc

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