Save This Page
Home » mojarra-1.2_09-b02-FCS-source » com.sun.faces.lifecycle » [javadoc | source]
    1   /*
    2    * $Id: RenderResponsePhase.java,v 1.26.4.1 2007/12/17 21:14:37 rlubke Exp $
    3    */
    4   
    5   /*
    6    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    7    * 
    8    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   // RenderResponsePhase.java
   42   
   43   package com.sun.faces.lifecycle;
   44   
   45   
   46   import javax.faces.FacesException;
   47   import javax.faces.application.FacesMessage;
   48   import javax.faces.context.FacesContext;
   49   import javax.faces.event.PhaseId;
   50   
   51   import java.io.IOException;
   52   import java.util.HashSet;
   53   import java.util.Iterator;
   54   import java.util.Set;
   55   import java.util.logging.Level;
   56   import java.util.logging.Logger;
   57   
   58   import com.sun.faces.util.TypedCollections;
   59   import com.sun.faces.util.FacesLogger;
   60   import com.sun.faces.util.RequestStateManager;
   61   
   62   
   63   /**
   64    * <B>Lifetime And Scope</B> <P> Same lifetime and scope as
   65    * DefaultLifecycleImpl.
   66    *
   67    * @version $Id: RenderResponsePhase.java,v 1.26.4.1 2007/12/17 21:14:37 rlubke Exp $
   68    */
   69   
   70   public class RenderResponsePhase extends Phase {
   71   
   72   
   73       // Log instance for this class
   74       private static Logger LOGGER = FacesLogger.LIFECYCLE.getLogger();
   75   
   76   
   77       // ---------------------------------------------------------- Public Methods
   78   
   79   
   80       public void execute(FacesContext facesContext) throws FacesException {
   81   
   82           if (LOGGER.isLoggable(Level.FINE)) {
   83               LOGGER.fine("Entering RenderResponsePhase");
   84           }
   85           if (LOGGER.isLoggable(Level.FINE)) {
   86               LOGGER.fine("About to render view " +
   87                    facesContext.getViewRoot().getViewId());
   88           }
   89           try {
   90               //Setup message display LOGGER.
   91               if (LOGGER.isLoggable(Level.INFO)) {
   92                   Iterator<String> clientIdIter = facesContext.getClientIdsWithMessages();
   93   
   94                   //If Messages are queued
   95                   if (clientIdIter.hasNext()) {
   96                       Set<String> clientIds = new HashSet<String>();
   97   
   98                       //Copy client ids to set of clientIds pending display.
   99                       while (clientIdIter.hasNext()) {
  100                           clientIds.add(clientIdIter.next());
  101                       }
  102                       RequestStateManager.set(facesContext,
  103                                               RequestStateManager.CLIENT_ID_MESSAGES_NOT_DISPLAYED,
  104                                               clientIds);
  105                   }
  106               }
  107   
  108               //render the view
  109               facesContext.getApplication().getViewHandler().
  110                    renderView(facesContext, facesContext.getViewRoot());
  111   
  112               //display results of message display LOGGER
  113               if (LOGGER.isLoggable(Level.INFO) &&
  114                    RequestStateManager.containsKey(facesContext,
  115                                                    RequestStateManager.CLIENT_ID_MESSAGES_NOT_DISPLAYED)) {
  116   
  117                   //remove so Set does not get modified when displaying messages.
  118                   Set<String> clientIds = TypedCollections.dynamicallyCastSet(
  119                        (Set) RequestStateManager.remove(facesContext,
  120                                                         RequestStateManager.CLIENT_ID_MESSAGES_NOT_DISPLAYED),
  121                        String.class);
  122                   if (!clientIds.isEmpty()) {
  123   
  124                       //Display each message possibly not displayed.
  125                       StringBuilder builder = new StringBuilder();
  126                       for (String clientId : clientIds) {
  127                           Iterator<FacesMessage> messages = facesContext.getMessages(clientId);
  128                           while (messages.hasNext()) {
  129                               FacesMessage message = messages.next();
  130                               builder.append("\n");
  131                               builder.append("sourceId=").append(clientId);
  132                               builder.append("[severity=(").append(message.getSeverity());
  133                               builder.append("), summary=(").append(message.getSummary());
  134                               builder.append("), detail=(").append(message.getDetail()).append(")]");
  135                           }
  136                       }
  137                       LOGGER.log(Level.INFO, "jsf.non_displayed_message", builder.toString());
  138                   }
  139               }
  140           } catch (IOException e) {
  141               throw new FacesException(e.getMessage(), e);
  142           }
  143           if (LOGGER.isLoggable(Level.FINE)) {
  144               LOGGER.fine("Exiting RenderResponsePhase");
  145           }
  146   
  147       }
  148   
  149   
  150       public PhaseId getId() {
  151   
  152           return PhaseId.RENDER_RESPONSE;
  153   
  154       }
  155   
  156   
  157   // The testcase for this class is TestRenderResponsePhase.java
  158   
  159   } // end of class RenderResponsePhase

Save This Page
Home » mojarra-1.2_09-b02-FCS-source » com.sun.faces.lifecycle » [javadoc | source]